gpt4 book ai didi

android - 此标签及其子标签可以替换为一个 和一个复合可绘制对象 : picture and text

转载 作者:行者123 更新时间:2023-11-29 21:11:24 25 4
gpt4 key购买 nike

我有这个代码

<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:background="@drawable/tick"
android:contentDescription="img" />

<TextView
android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="text1 "
android:textColor="#fff"
android:textSize="@dimen/sizeNormal" />

我有一个警告 This tag and its children can be replaced by one <TextView/> and a compound drawable

如何将它们合并到一个 TextView 中?

我试过了,但同时我遇到了勾选图像尺寸问题。

这里你可以看到图片

enter image description here

最佳答案

只是一个警告,应用程序应该仍然可以编译和运行。但是,这并不意味着您只想忽略所有警告。

现在,有不同的方法可以做到这一点。您可以在 xml 中使用 drawableLeft。有点像

<TextView
android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="text1 "
android:textColor="#fff"
android:textSize="@dimen/sizeNormal"
android:drawableLeft="@drawable/tick />

您还可以看到 here in the docs在您的 Java 代码中调整它的不同方法。

要设置图像和文本之间的填充,请尝试使用

yourTextView.setCompoundDrawablePadding(somePadding);  

其中 somePadding 是一个 int,代表您想要的 padding 的值。

关于android - 此标签及其子标签可以替换为一个 <TextView/> 和一个复合可绘制对象 : picture and text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22702094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com