My Android Advanced Tour------>android A preliminary understanding of Imagespan and spannablestring

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-size:24px"><span style="white-space:pre"></span>Recently to implement a similar <span style="color:rgb(61,61,61); font-family:Arial,Helvetica,simsun,u5b8bu4f53; line-height:25px">QQ chat input box, in the input box can enter both text and expression image Function. As shown in the Effect:</span></span></p></p><p style="text-align:center"><p style="text-align:center"><span style="font-size:24px"><span style="color:rgb(61,61,61); font-family:Arial,Helvetica,simsun,u5b8bu4f53; line-height:25px"><br></span></span></p></p><p style="text-align:left"><p style="text-align:left"><span style="font-size:24px"><span style="color:rgb(61,61,61); font-family:Arial,Helvetica,simsun,u5b8bu4f53; line-height:25px">In order to achieve this effect, first to understand the use of Imagespan and Spannablestring. Here is a small example to look at the specific usage, the effect is as Follows:</span></span></p></p><p style="text-align:center"><p style="text-align:center"><span style="font-size:24px"><span style="color:rgb(61,61,61); font-family:Arial,Helvetica,simsun,u5b8bu4f53; line-height:25px"><br></span></span></p></p><p style="text-align:left"><p style="text-align:left"><span style="font-size:24px"><span style="color:rgb(61,61,61); font-family:Arial,Helvetica,simsun,u5b8bu4f53; line-height:25px">The code is as Follows:</span></span></p></p><p style="text-align:left"><p style="text-align:left"><span style="font-size:24px"><span style="color:rgb(61,61,61); font-family:Arial,Helvetica,simsun,u5b8bu4f53; line-height:25px"></span></span></p></p><pre name="code" class="java"><pre name="code" class="java">@Overrideprotected void onCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( r.layout.activity_main); TextView Mdetailview = (TextView) Findviewbyid (r.id.detail); String Text = "hello everyone, laugh more, like this [smile]"; imagespan imagespan=new imagespan (this, r.drawable.smile); spannablestring spannablestring = new spannablestring (text); spannablestring.setspan (imagespan, text.indexOf (' ['), Text.indexof ('] ') + 1,spannable.span_exclusive_exclusive); mdetailview.settext (spannablestring);}</pre></pre><br><br><p><p></p></p><span style="font-size:24px">the <span style="font-size:24px">main code is to replace the [smile] text with the r.id.smile image</span></span><p><p></p></p><p style="text-align:left"><p style="text-align:left"><span style="font-size:24px"><span style="color:rgb(61,61,61); font-family:Arial,Helvetica,simsun,u5b8bu4f53; line-height:25px"><br>Layout file:</span></span></p></p><p style="text-align:left"><p style="text-align:left"><span style="font-size:24px"><span style="color:rgb(61,61,61); font-family:Arial,Helvetica,simsun,u5b8bu4f53; line-height:25px"></span></span></p></p><pre name="code" class="html"><pre name="code" class="html"><relativelayout 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:paddingbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_ Horizontal_margin " android:paddingright=" @dimen/activity_horizontal_margin " android:paddingtop=" @dimen /activity_vertical_margin " tools:context=". Mainactivity "> <textview android:id=" @+id/detail " android:layout_width=" wrap_content " android:layout_height= "wrap_content" android:text= "@string/hello_world"/></relativelayout></pre></pre><br><span style="color:rgb(51,51,51); font-family:KaiTi_GB2312; font-size:18px; line-height:26px; text-align:center; background-color:rgb(254,254,242)"><span style="color:rgb(51,51,51); font-family:KaiTi_GB2312; font-size:18px; line-height:26px; text-align:center; background-color:rgb(254,254,242)">==================================================================================================</span></span><br><p><p></p></p><p style="text-align:left"><p style="text-align:left"><span style="font-size:24px">As to achieve the first figure shown in the QQ chat input box effect, you need to find more than one QQ expression picture, and then the corresponding text, with a map<string key,integer value> to store up. Then use the grid layout, all the expressions are related to the zoom effect after the display, but also to use the paging technology, as well as add three-dimensional flip effect effects, and so on, there is no Code.</span></p></p><p style="text-align:left"><p style="text-align:left"><span style="font-size:24px">You can refer to the relevant blog online:</span></p></p><p style="text-align:left"><p style="text-align:left"><span style="font-size:24px">Android UI "android imitation, QQ chat, with emoticons, can flip, with page drag buffer"</span></p></p><p style="text-align:left"><p style="text-align:left"><span style="font-size:24px">Address: http://blog.csdn.net/lnb333666/article/details/8546497</span></p></p><p style="text-align:left"><p style="text-align:left"><span style="font-size:24px"></span></p></p><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; color:rgb(51,51,51); text-align:center; background-color:rgb(254,254,242)"><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; color:rgb(51,51,51); text-align:center; background-color:rgb(254,254,242)"><span style="font-family:KaiTi_GB2312"><span style="font-size:18px">==================================================================================================</span></span></p></p><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; color:rgb(51,51,51); text-align:center; background-color:rgb(254,254,242)"><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; color:rgb(51,51,51); text-align:center; background-color:rgb(254,254,242)"><span style="font-family:KaiTi_GB2312"><strong><span style="font-size:18px">Ouyangpeng welcome reprint, sharing with people is the source of progress!</span></strong></span></p></p><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; color:rgb(51,51,51); text-align:center; background-color:rgb(254,254,242)"><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; color:rgb(51,51,51); text-align:center; background-color:rgb(254,254,242)"><span style="font-family:KaiTi_GB2312"><strong><span style="font-size:18px">Reprint please keep the original address <span style="color:rgb(153,51,153)">: Http://blog.csdn.net/ouyang_peng</span></span></strong></span></p></p><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; color:rgb(51,51,51); text-align:center; background-color:rgb(254,254,242)"><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; color:rgb(51,51,51); text-align:center; background-color:rgb(254,254,242)"><span style="font-family:KaiTi_GB2312"><span style="font-size:18px">==================================================================================================</span></span> <span style="color:rgb(85,85,85); font-family:‘microsoft yahei‘; line-height:35px; font-size:12px; background-color:rgb(248,248,248)">  </span></p></p><br> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>My Android Advanced Tour------>android A preliminary understanding of Imagespan and spannablestring</p></p></span>

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.