Android TextView Graphics Mixed choreography

Source: Internet
Author: User

Android TextView Graphics mixed choreography
The technical details are not difficult to achieve, two key points:
1, the combination of HTML code to write.
2, rewrite Imagegetter.


For example:
Layout:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "xmlns:tools=" Http://schemas.android.com/tools "android:layout_width=" Match_parent "android:layout_height        = "Match_parent" android:orientation= "vertical" tools:context= "zhangphil.app.MainActivity" > <textview Android:id= "@+id/text1" android:layout_width= "wrap_content" android:layout_height= "Wrap_content"/> & Lt TextView android:id= "@+id/text2" android:layout_width= "wrap_content" android:layout_height= "Wrap_cont Ent "/> <textview android:id=" @+id/text3 "android:layout_width=" Wrap_content "android:layout _height= "Wrap_content" android:ellipsize= "End" android:maxlines= "1"/> <textview android:id= "@+id/text4" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:ellipsi Ze= "End" Android:maxlines= "1"/></linearlayout> 



Java code:
Package Zhangphil.app;import Android.graphics.drawable.drawable;import Android.support.v4.content.ContextCompat; Import Android.support.v7.app.appcompatactivity;import Android.os.bundle;import Android.text.html;import Android.widget.textview;public class Mainactivity extends Appcompatactivity {@Override protected void onCreate (Bund        Le Savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        TextView Text1 = (TextView) Findviewbyid (R.ID.TEXT1);        TextView Text2 = (TextView) Findviewbyid (R.ID.TEXT2);        TextView Text3 = (TextView) Findviewbyid (R.ID.TEXT3);        TextView Text4 = (TextView) Findviewbyid (R.ID.TEXT4);        String s = "Zhang Phil @ csdn Android TextView graphics and text";        Charsequence CS1 = html.fromhtml (StringMixWithImage1 (s), imgagegetter, NULL);        Text1.settext (CS1);        Charsequence CS2 = html.fromhtml (StringMixWithImage2 (s), imgagegetter, NULL);        Text2.settext (CS2); Charsequence cs3 = html.fromhtml (StringMixWithImage3 (s), imgagegetter, NULL);        Text3.settext (CS3);        charsequence cs4 = html.fromhtml (StringMixWithImage4 (s), imgagegetter, NULL);    Text4.settext (CS4); } private String StringMixWithImage1 (String string) {return String + "1" + " ' + ' + '  ' + ' + '  "+" + " "+" + " ' + ' + '  ' + ' + '  "+    "" + string; } private Html.imagegetter Imgagegetter = new Html.imagegetter () {@Override public drawable getdrawable (            String source) {int id = integer.parseint (source);            drawable d = contextcompat.getdrawable (Getapplicationcontext (), id);            D.setbounds (0, 0, d.getintrinsicwidth (), D.getintrinsicheight ());        return D; }    };}



Code Run Result:


Android TextView Graphics Mixed choreography

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.