2012-01-03 2 views
6

내 레이아웃에는 ImageView (iv)와 TextView (tv)가 있습니다. 나는 iv의 tv 권리를시키고 싶다. 그리고 tv의 높이는 iv와 같습니다. tv Gravity가 CENTER_VERTICAL로 설정되었습니다.ImageView와 TextView의 높이를 같게하는 방법

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/RelativeLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 


    <ImageView 
     android:id="@+id/iv" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true"/> 


    <TextView 
     android:id="@+id/tv" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_toRightOf="@+id/iv" 
     android:text="TextView" android:gravity="center_vertical"/> 

</RelativeLayout> 

목표를 달성하는 방법?

+1

당신의 LinearLayout를 사용할 수 RelativeLayout 대신 layout_weight 매개 변수를 ImageView와 TextView에 모두 1로 사용할 수 있습니다. –

+0

두 높이가 같은 위젯을 어떻게 얻을 수 있습니까? 텍스트 뷰의 높이는 텍스트 크기에 따라 다릅니다. 우리는 나란히 서서 갈 수 있습니다. 우리는 같은 높이를 보장 할 수 없습니다. –

답변

20

안녕하세요이 시도 android:layout_alignBottom="@id/iv"을 .....

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/RelativeLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ImageView 
    android:id="@+id/iv" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:src="@drawable/ic_title_home_demo" /> 

    <TextView 
    android:id="@+id/tv" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/iv" 
    android:layout_alignTop="@+id/iv" 
    android:layout_toRightOf="@+id/iv" 
    android:gravity="center_vertical" 
    android:text="TextView" /> 

    </RelativeLayout> 
1

글자를 정확히 세로로 가운데 맞추려면 TextView 태그에서 android:layout_alignParentTop="true" 줄을 제거해야합니다.

그러나 ImageView의 전체 높이에 맞게 텍스트 크기를 변경하려고하는 것처럼 들릴 수 있습니다. 이것은 분명히 그것을 해결하지는 못 하겠지만, 처음에는 그렇게하지 않는 것이 좋을 것 같습니다.

1

당신은

안드로이드를 사용하여 서로 다른 크기를 사용할 수 있습니다 : layout_width = "wrap_content"

및/또는

안드로이드 : 높이 = "300dp"

(높이가 같음). 또한 마진 및 패딩을 확인하십시오. 동일한 폭이 2 개 버튼셔서 즉 layout_weight를하고 설정합니다 부모 뷰의 가로 공간 채우기 : 더 동적해야하는 경우

, 당신은 안드로이드 고려해 볼 수 있습니다

안드로이드 : layout_height = "를 wrap_content "

android_layout : weight ="0.5 "

이 링크 따를 수

: How to make two different layout to have same height?

4
당신은 android:layout_alignTop="@id/iv"에 텍스트 뷰 속성을 설정해야합니다

관련 문제