的TextView />这标记及其子可以由一个与所述被取代;和复合绘制:图片和文字所述、其子、标记、文字

2023-09-06 08:42:14 作者:少壮不努力,长大抢小米

我有这样的codeS

I have this codes

<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" />

和我有一个警告此标记和它的孩子们可以通过吲代替; TextView的/&GT;和复合绘制

我怎样才能将它们合并一个TextView的?

How i can merge them to one textview?

我已经试过,但在同一时间,我已经打勾图像尺寸的问题。

i have tried but in the same time i have tick image dimension problem.

在这里你可以看到图像

推荐答案

此的是的只是一个警告和应用程序仍然应该编译和运行。但是,这并不意味着你只是想关闭所有警告。

This is just a warning and the app should still compile and run. However, this doesn't mean that you just want to dismiss all warnings.

现在,也有不同的方法来做到这一点。你可以在你的XML使用 drawableLeft 。类似

Now, there are different ways to do this. You could use drawableLeft in your xml. Something like

<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 />

您还可以看到在这里的在Java code调整它的不同方式的文档。

You can also see here in the docs of different ways of adjusting it in your Java code.

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

To set the padding between the image and the text, try using

yourTextView.setCompoundDrawablePadding(somePadding);  

其中, somePadding INT 填充值你想要的。