Android TextView SetText A deep reason for Kaka

Source: Internet
Author: User

Recently found in the company project inside the ListView TextView is very time-consuming to call the SetText function, it was a little unbelievable, because if you set TextView to Wrap_content, then each call to SetText will be called to

........ 40334034            if (mmovement! = null) {4035                mmovement.initialize (This, (spannable) text); 40364037                /*4038                 * Initializing the movement method would have a set the4039                 * selection, so reset mselectionmoved to keep that from4040
   
    * interfering with the normal on-focus selection-setting.4041                 */4042                if (meditor! = null) meditor.mselectionmoved = false;4043            }4044        }40454046        if (mlayout! = null) {
   
                This function is very important 4047            checkforrelayout (); 4048        }40494050        sendontextchanged (text, 0, Oldlen, textLength); 4051        ontextchanged (text, 0, Oldlen, textLength); 40524053        notifyviewaccessibilitystatechangedifneeded ( Accessibilityevent.content_change_type_text); 4054
.........
The Checkforrelayout function, which re-starts layout based on how much text is

6807 private void More ... checkforrelayout () {6808//If We have a fixed width, we can just swap in a new text L ayout6809//If the text height stays the same or if the view height is fixed.68106811 if (mlayoutparams.wi DTH! = Layoutparams.wrap_content | | 6812 (Mmaxwidthmode = = Mminwidthmode && mmaxwidth = = mminwidth)) &&6813 (mHi NT = = NULL | | Mhintlayout = null) &&6814 (Mright-mleft-getcompoundpaddingleft ()-Getcompoundpaddingright () > 0) {6815//Static width, so try making a new text layout.68166817 int oldht = Mlayout.getheig HT (); 6818 int want = Mlayout.getwidth (); 6819 int hintwant = Mhintlayout = null?  0:mhintlayout.getwidth (); 68206821/*6822 * No need to bring the text in view, since the size is not6823 * Changing (unless we do the requestlayout (), in which case it6824 * would happen aT measure). 6825 */6826 makenewlayout (Want, Hintwant, unknown_boring, unknown_boring,6827 Mright-mleft-getcompoundpaddingleft ()-Getcompoundpaddingright (), 6828 false);  68296830 if (mellipsize! = TextUtils.TruncateAt.MARQUEE) {6831//In a fixed-height view, so use                    Our new text layout.6832 if (mlayoutparams.height! = layoutparams.wrap_content &&6833 Mlayoutparams.height! = layoutparams.match_parent) {6834 invalidate (); 6835 re  turn;6836}68376838//Dynamic height, but height has stayed the same,6839// So with our new text layout.6840 if (mlayout.getheight () = = Oldht &&6841 (mhintl Ayout = = NULL | |                Mhintlayout.getheight () = = Oldht)) {6842 invalidate (); 6843 return;6844 }6845            }68466847//We lose:the height has changed and we have a dynamic height.6848//Reques T a new view layout using our new text layout.6849 requestlayout (); 6850 invalidate (); 6851} E LSE {6852//Dynamic width, so we had no choice but to request a new6853//view layout with a new    Text layout.6854 nulllayouts (); 6855 requestlayout (); 6856 invalidate (); 6857}6858 }

The note has been written very clearly, so the width is set to a number or match_parent can make the settext time to shorten, that is.

Android TextView SetText A deep reason for Kaka

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.