We know that the TextView control is generally used to display text, and image is usually with ImageView control to display,
The TextView can display images? The answer is yes! Below is a list of common four way,
Specified in the XML file attribute values
This way should be the most commonly used, in the upper right in the TextView display images, available
Android: drawableLeft
Android: drawableTop
Android: drawableRight
Android: drawableBottom
We want to set at the top of the TextView images, for example, the code is as follows:
Android: layout_width="wrap_content"
Android: layout_height="wrap_content"
Android: drawableTop="@ drawable/ic_launcher"
Android: text="hello_world"/& gt;
1
2
3
4
5
6
This kind of display mode is center aligned images and text, the corresponding method is setCompoundDrawablesWithIntrinsicBounds:
MTextView01. SetCompoundDrawablesWithIntrinsicBounds (null,
GetResources (). GetDrawable (R.d rawable. Ic_launcher, null), null, null);
1
2
Effect:
If you find pictures from too close, and can set the spacing between them, can be implemented in the XML or code:
Android: drawablePadding="10 dp"
1
Or
MTextView01. SetCompoundDrawablePadding (10);
1
By parsing HTML to display a picture
This method can display images in the project, the local SDCARD and network picture, the picture of the network, of course, you must first and then downloaded to a local display,
According to project the picture
Look at the code
//second way: display in the project