How do I use a compound drawable instead of a LinearLayout that contains an ImageView and a TextView How do I use a compound drawable instead of a LinearLayout that contains an ImageView and a TextView android android

How do I use a compound drawable instead of a LinearLayout that contains an ImageView and a TextView


TextView comes with 4 compound drawables, one for each of left, top, right and bottom.

In your case, you do not need the LinearLayout and ImageView at all. Just add android:drawableLeft="@drawable/up_count_big" to your TextView.

See TextView#setCompoundDrawablesWithIntrinsicBounds for more info.


if for some reason you need to add via code, you can use this:

mTextView.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom);

where left, top, right bottom are Drawables