Android Graphics together TextView spannablestring and Imagespan class use

Source: Internet
Author: User

Today, let's talk about Spannablestring and Imagespan class.

Bitmap Bitmap = null;
Bitmap = Bitmapfactory.decoderesource (Getresources (), imageids[arg2% imageids.length]);

The first parameter includes the entire picture resource, and the second specifies an ID
Imagespan Imagespan = new Imagespan (neighborcommunicationmessageactivity.this, bitmap);

//edit box to add pictures to the class, Let the picture replace the specified text, such as hehe is actually equivalent to can be replaced by each other. I'll let you choose when you type.

String str = NULL;
if (arg2<10) {
str = "F00" +ARG2;
}else if (arg2<100) {
str = "F0" +ARG2;
}else{
str = "F" +ARG2;
}

spannablestring spannablestring = new spannablestring (str);
Spannablestring.setspan (Imagespan, 0, 4, spannable.span_exclusive_exclusive);

//
Content.append (spannablestring);


TextView combined with spannablestring the use of the encyclopedia inside there is aReplace text with ImagespanThe specific is:spannablestring ss = new Spannablestring ("CCCCCCCCCCCCC stepping");
drawable d = getresources (). getdrawable (R.drawable.icon);
d.setbounds (0, 0, d.getintrinsicwidth (), D.getintrinsicheight ());
//Create Imagespan
Imagespan span = new Imagespan (d, imagespan.align_baseline);
//Replace text with Imagespan
Ss.setspan (span,,, spannable.span_inclusive_exclusive);
Txtinfo.settext (ss);

At this time Content.append (spannablestring), actually is the picture expression into edittext inside.


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.