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