Using a Compound Drawable
In Chapter: Graphical User Interface
Author: Julien Quiévreux ('letroll')
How do I use a "compound drawable", a TextView that contains an ImageView in addition to its text?
Use one of the attributes such as android:drawableLeft="@drawable/up_count_big" to your TextView.
To integrate an image to your textview you must know where you want it, then use the appropriate property:
android: drawableLeft : to place your image on the left of the text.
Here is an example of use in a layout xml:
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: text = "@ string/text"
android: drawableTop = "@drawable/ic_launcher"
android: gravity = "center" />
Here is an example of configuring the drawable in the code:
TextView tv = (TextView) findViewById (R.id.textView);
R.drawable.ic_launcher, 0, 0);
If you found this recipe useful, why not
buy the book
and have the whole collection always at hand?"