如何使用复合可绘制对象而不是包含 ImageView 和 TextView 的 LinearLayout [英] How do I use a compound drawable instead of a LinearLayout that contains an ImageView and a TextView

查看:37
本文介绍了如何使用复合可绘制对象而不是包含 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.

就您而言,您根本不需要 LinearLayoutImageView.只需将 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.

这篇关于如何使用复合可绘制对象而不是包含 ImageView 和 TextView 的 LinearLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆