2014-01-30 1 views
0

어떻게 정확히 같은 아이콘과 텍스트 레이아웃 수레이아웃 그리기 excat와 텍스트 및 확대됨은

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="64dp" 
    android:layout_height="64dp"> 
    <ImageView 
     android:id="@+id/imgIcon" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="8dp" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginBottom="24dp" 
     android:duplicateParentState="true" 
     android:src="@drawable/delete_icon" /> 
    <TextView 
     android:id="@+id/txtLabel" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:gravity="center_horizontal" 
     android:duplicateParentState="true" 
     android:text="xxx" /> 
</RelativeLayout> 

그러나 Android guide 말한다 : 컴파운드 드로어 블 사용 - ImageView와 TextView가 포함 된 LinearLayout을 복합 드로어 블로 효율적으로 처리 할 수 ​​있습니다. 시도했지만, 필요한 레이아웃 매개 변수 (이미지의 크기, 이미지 및 텍스트의 다른 패딩)를 찾을 수 없습니다.

필요한 파라미터를 제공하고보다 나은 기준 성분이있는 경우

enter image description here

, 너무 허용이다 : 여기

<TextView 
    android:id="@+id/txtLabel" 
    android:layout_width="64dp" 
    android:layout_height="64dp" 
    android:layout_alignParentBottom="true" 
    android:gravity="center_horizontal|bottom" 
    android:duplicateParentState="true" 
    android:drawableTop="@drawable/delete_icon" 
    android:paddingTop="8dp" 
    android:drawablePadding="8dp" 
    android:text="xxx" /> 

(오른쪽 화합물 그리기와 RelativeLayout의 왼쪽)의 결과이다.

답변

0

나는 똑같이하려고 노력했다.
나는이 결과를 가지고 은 (이미지가 실제 이미지 크기보다 작은 "광학 광장"이 점에 유의하시기 바랍니다) : 화합물 드로어 블 : 내 마음에 드는 방법을 사용하고

enter image description here

.

그러나이 : ​​

1 - 나는 xxhdpi 96 * 96 픽셀의 폭 (32 * 32 표준 MDPI (160dpi) 해상도라고 있도록, 서로 다른 해상도에서 일부 이미지를 준비하고, 서로 다른 해상도로 스케일링 및 ture) - 2 - 이미지를 해당 드로어 블 폴더 (drawable-ldpi ~ drawable-xxhdpi)에 배치했습니다. 3 - 레이아웃을 약간 수정하여 일치시킵니다.

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#fff" 
    android:layout_margin="0dp" 
    android:padding="0dp" 
    > 
    <TextView 
     android:id="@+id/txtLabel" 
     android:layout_width="64dp" 
     android:layout_height="64dp" 
     android:layout_alignParentBottom="true" 
     android:gravity="center_horizontal|bottom" 
     android:padding="8dp" 
     android:drawableTop="@drawable/delete_icon" 
     android:drawablePadding="4dp" 
     android:text="XXX" 
     android:textSize="12sp" 
    /> 
</RelativeLayout> 

텍스트와 드로어 블 간의 간격을 더 잘 나타 내기 위해 대문자를 모두 사용했습니다.
귀하의 요구 사항에 맞습니까?