Android textview text scaling effect with arrows

Source: Internet
Author: User

Android textview text scaling effect with arrows

Although I did it myself or didn't quite understand it, I just read the online method and summarized it myself. If you have a good demo, please share it.

The main method is to restrict the xml file by using several variables without Pasting a common TextView.

 

Public class TextViewActivity extends Activity {private TextView TV; private String status = "up"; private String str = "Android is a Linux-based free and open-source operating system, mainly used for mobile devices, such as smartphones and tablets, led and developed by Google and the Open Mobile Alliance. "; Private String str_show =" "; private int maxlength = 50; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); TV = (TextView) findViewById (R. id. textView1); if (str. length () <maxlength) {TV. setText (str) ;}else {changStatus () ;}} private void changStatus () {TV. setText (""); Drawable drawable = null; if (status. equals ("down") {drawable = getResources (). getDrawable (R. drawable. icon_arrow_up); status = "up"; str_show = str; TV. setMaxLines (10000);} else if (status. equals ("up") {drawable = getResources (). getDrawable (R. drawable. icon_arrow_down); status = "down"; TV. setMaxLines (2); str_show = str. substring (0, maxlength); str_show + = "... ";}string spanString = str_show; spanString = spanString. substring (0, spanString. length (); drawable. setBounds (0, 0, drawable. getIntrinsicWidth (), drawable. getIntrinsicHeight (); SpannableString spannable = new SpannableString (spanString. toString () + "s"); ImageSpan span = new ImageSpan (drawable, ImageSpan. ALIGN_BASELINE); spannable. setSpan (span, spanString. toString (). length (), spanString. toString (). length () + "s ". length (), Spannable. SPAN_INCLUSIVE_EXCLUSIVE); ClickableSpan rightClickableSpan = new ClickableSpan () {@ Overridepublic void onClick (View view) {changStatus () ;}; spannable. setSpan (rightClickableSpan, spanString. toString (). length (), spanString. toString (). length () + "s ". length (), Spannable. SPAN_INCLUSIVE_EXCLUSIVE); TV. setText (spannable); TV. setMovementMethod (new MyTouch ());}}


 

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.