如何使用复合可绘制对象而不是包含 ImageView 和 TextView 的 LinearLayout
针对我的代码运行新的 Lint 工具.它提出了很多很好的建议,但我看不懂.
Ran the new Lint tool against my code. It came up with a lot of good suggestions, but this one I cannot understand.
这个标签和它的子标签可以被一个和一个复合drawable替换
This tag and its children can be replaced by one and a compound drawable
问题:检查当前节点是否可以使用复合可绘制对象替换为 TextView.
Issue: Checks whether the current node can be replaced by a TextView using compound drawables.
包含 ImageView 和 TextView 的 LinearLayout 可以更有效地作为复合可绘制对象进行处理
A LinearLayout which contains an ImageView and a TextView can be more efficiently handled as a compound drawable
这是我的布局
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerInParent="true">
<ImageView
android:id="@+id/upImage"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:scaleType="centerInside"
android:src="@drawable/up_count_big">
</ImageView>
<TextView
android:id="@+id/LikeCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginBottom="1dp"
android:textColor="@color/gray"
android:textSize="16sp"
android:layout_gravity="center_vertical">
</TextView>
</LinearLayout>
谁能提供一个具体的例子来说明在这种情况下如何使复合可绘制?
Can someone provide a concrete example of how to make a compound drawable in this case?
TextView
带有 4 个复合可绘制对象,左、上、右、下各一个.
TextView
comes with 4 compound drawables, one for each of left, top, right and bottom.
就您而言,您根本不需要 LinearLayout
和 ImageView
.只需将 android:drawableLeft="@drawable/up_count_big"
添加到您的 TextView
.
In your case, you do not need the LinearLayout
and ImageView
at all. Just add android:drawableLeft="@drawable/up_count_big"
to your TextView
.
参见 TextView#setCompoundDrawablesWithIntrinsicBounds 了解更多信息.
See TextView#setCompoundDrawablesWithIntrinsicBounds for more info.