How to Set a Drawable to the left of the text, in TextView, in XML
android:drawableLeft was added in API Level 1Related Method: setCompoundDrawablesWithIntrinsicBounds - Add a Drawable to the Left of the text in a TextView, in Java
The drawable to be drawn to the left of the text.
1. Add a drawable named myImage.
2. Add a TextView.
3. Add the following text to the TextView: "This is an example with a drawable set to the right in a TextView."
4. Set the android:layout_width of the TextView to wrap_content.
4. In the main.xml file, add the below line
<TextView
....
android:drawableRight = "@drawable/myImage"
/>
5. Compile and run!
This is using android:drawableRight, with android:layout_width = "wrap_content" |
6. You can also change the android:layout_width to match_parent, and you get the result below.
This is using android:drawableRight with android:layout_width = "match_parent" |
Related Articles
- setCompoundDrawablesWithIntrinsicBounds - Add a Drawable Below a TextView
- Set an Image to Background of a TextView, using background
http://developer.android.com/reference/android/widget/TextView.html#attr_android:drawableRight
http://developer.android.com/reference/android/R.attr.html#drawableRight