1

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

and i am having a warning This tag and its children can be replaced by one <TextView/> and a compound drawable

How i can merge them to one textview?

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

here you can see the image

enter image description here

lospicos
  • 301
  • 5
  • 16
  • possible duplicate of [How do I use a compound drawable instead of a LinearLayout that contains an ImageView and a TextView](http://stackoverflow.com/questions/8318765/how-do-i-use-a-compound-drawable-instead-of-a-linearlayout-that-contains-an-imag) – donfuxx Mar 28 '14 at 00:49
  • I have hecked also. But itis not solution for me as we nned to resize the tickimg – lospicos Mar 28 '14 at 01:01

2 Answers2

2

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.

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

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);  

where somePadding is an int for the value of the padding you want.

codeMagic
  • 44,549
  • 13
  • 77
  • 93
1

USe the text Compound Drawables.

<TextView
    android:id="@+id/txtTitle"
    android:drawableLeft="@drawable/g_device_access_storage"
    android:drawableRight="@drawable/g_navigation_refresh"
    android:paddingRight="55dp"
    android:text="hello" />
rupps
  • 9,712
  • 4
  • 55
  • 95