Display picture information with HTML-tagged text:
Import Java.lang.reflect.field;import Android.app.activity;import Android.graphics.color;import Android.graphics.drawable.drawable;import Android.os.bundle;import Android.text.html;import Android.text.html.imagegetter;import Android.text.method.linkmovementmethod;import Android.view.Menu;import Android.view.menuitem;import Android.widget.textview;public class Mainactivity extends Activity {private int Getresousid (String name) {///TODO auto-generated method stub//genjiu The ID variable name of the resource, gets the Field object, uses the reflection mechanism to implement the//field is the field property, The property value used to store a class field Field;try {//Class.getfield (String name)//is used to return a property of the specified name, but this property must be public, and this property can be defined in the parent class. If the property is private or protected, an exception is thrown that does not find the attribute field = R.drawable.class.getfield (name);//The value of the field (static variable) that gets and returns the ID of the resource, using the reflection mechanism return Integer.parseint (Field.get (null). ToString ());} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();} return 0;} @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); TextviEW TextView = (textView) Findviewbyid (R.id.textview); Textview.settextcolor (Color.Blue); String html = "Image 1 </a> '; Charsequence charsequence = html.fromhtml (Html, New Imagegetter () {@Override/* * Get information about the system's resources, slice information This method will be used three times in this program because it is three images (non -javadoc) * * @see android.text.html.imagegetter#getdrawable (java.lang.String) */public drawable getdrawable (String SOURCE) {//TODO auto-generated method stub//Get information about system resources drawable drawable = Getresources (). Getdrawable (Getresousid ( SOURCE);//Image03 Scaling if (source.equals ("image03")) {//SetBounds is used to set the property is worth the left upper right Bottom//getintrinsicwidth () to get the actual width D Rawable.setbounds (0, 0, drawable.getintrinsicwidth ()/2,drawable.getintrinsicheight ()/2);} else {drawable.setbounds (0, 0, drawable.getintrinsicwidth (), Drawable.getintrinsicheight ());} return drawable;}}, NULL); Textview.settext (charsequence);//Click Response TEXTVIew.setmovementmethod (Linkmovementmethod.getinstance ());}}
Android------textview display picture information