我如何使用包含一个ImageView的和一个TextView一个LinearLayout中的化合物,而不是绘制

问题描述:

然对我的code中的新皮棉工具。它提出了很多很好的建议,但是这一个我无法理解。

Ran the new Lint tool against my code. It came up with a lot of good suggestions, but this one I cannot understand.

此标记和它的孩子们可以通过一个替代的化合物和可绘制

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.

一个的LinearLayout其含有的ImageView和一个TextView可以更有效地处理为可绘制的化合物

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 可言。只需添加安卓drawableLeft =@可绘制/ 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获取更多信息。