2013-07-12 5 views
2

어쨌든 TextView width 일치하는 컴파 운드 Drawable width (XML)? TextView 너비 일치 drawable 상단 너비

는 XML 코드에 대한 예를 들어 :

<TextView 
    android:id="@+id/textView" 
    style="@style/TextIcons" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:drawableTop="@drawable/icon_contact" 
    android:gravity="center" 
    android:lines="2" 
    android:text="@string/contact_label" /> 

내가 얻을 :

|---------------------| 
| |-------------| | 
| |    | | 
| | Drawable | | 
| | View  | | 
| |    | | 
| |-------------| | 
|[---Contact Label---]| 
|---------------------| 

하지만 내가 진정으로 원하는 것은 :

|-----------------| 
| |-------------| | 
| |    | | 
| | Drawable | | 
| | View  | | 
| |    | | 
| |-------------| | 
| [---Contact---] | 
| [----Label----] | 
|-----------------| 

답변

4

당신은 단순히 그것을 얻을 수 분리하여 일하다 이미지와 TextView를 상대적 레이아웃으로 변환합니다. 그것은 등 일부 뷰의 가장자리를 정렬 위치를 지정 쉽게

다음 코드는 당신이 원하는에 가까운 일을 수행해야합니다

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 

    <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/icon_contact" 
      android:id="@+id/imageView" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="10dp"> 

    </ImageView> 
    <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="@string/contact_label" 
      android:id="@+id/textView" 
      android:layout_below="@+id/imageView" 
      android:layout_alignRight="@+id/imageView" 
      android:layout_alignLeft="@+id/imageView"/> 
</RelativeLayout> 
+0

그것은 작동하지만 실제로 내가 정렬 두 줄이 남아있어, 센터 필요합니다. – GLopez

+0

TextView에 android : gravity = "center"만 추가했습니다. 감사합니다. 나는 더 단순한 것을 선호 하겠지만 외모는 선호하지 않습니다. – GLopez