【发布时间】:2014-01-30 07:48:20
【问题描述】:
我怎样才能用完全像这样的图标来布局文本:
我用这个布局做到了:
<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 可以更有效地作为复合可绘制对象处理。 我试过了,但我找不到我需要的布局参数(图像的大小、图像和文本的不同填充)。
<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,右边是复合drawable):
如果有更好的标准组件提供必要的参数,也是可以接受的。
【问题讨论】:
标签: android layout textview drawable