Android------textview display picture information

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.