Android 带有可绘制excat和performant的布局文本
我如何使用如下图标布局文本: 我是这样做的:Android 带有可绘制excat和performant的布局文本,android,layout,textview,drawable,Android,Layout,Textview,Drawable,我如何使用如下图标布局文本: 我是这样做的: <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_widt
<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>
但是,作者说:使用复合绘图-包含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,右侧为Composite drawable):
如果有更好的标准组件提供必要的参数,也可以接受。我也尝试过这样做。
我得到了这个结果(请注意,图像有一个“光学正方形”,它小于物理图像大小): 我用的是我最喜欢的方法:复合拉丝法 但是: 1-我准备了一些不同分辨率的图像,因此32*32是指标准的mdpi(160dpi)分辨率,并在不同分辨率下缩放(xxhdpi是96*96 px宽和高)- 2-我将这些图像放在相应的可绘制文件夹中(可绘制ldpi到可绘制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>
我使用了所有大写字母,以便更好地查看文本和可绘制文本之间的间距。它适合你的需要吗