Elementary Introduction: The Append method of Android TextView is used in conjunction with scroll bar

Source: Internet
Author: User
Tags message queue

First, inAndroid, a separateTextViewis not scrollable and needs to be placed in aScrollViewthe.
ScrollViewprovides a series of functions, whereFullscrollused to implementfocus_upand theFocus_downthe function of the key, which is scrolling to the top and bottom.

if theTextViewof theAppendcalled immediately afterFullscrolland will find it impossible to scroll to the real bottom, which is becauseAndroidThe next many functions are message-based and use Message Queuing to ensure synchronization, so the function calls are mostly asynchronous operations.
There is a message queue that is asynchronous, and Message Queuing scrolls to the bottom first, and thenTextViewof theAppendmethod is displayed. So I can't scroll to the bottom correctly.

Workaround:

finalscrollview scrollview =  (ScrollView)   Findviewbyid (R.id.scrollview1);       if  (scrollView != null )  {           scrollview.post (New Runnable ()  {                  Publicvoidrun ()  {                     scrollview.fullscroll (Scrollview.focus_down);                  }         });         } 

II , ListView listview Scroll, use the scroll bar to scroll to listview

put the above code Run In that sentence for this . Scrollview.scrollto (0,mlistviewlist.getheight ());

Third, ListView internal height calculation function

when ListView when used with a vertical scroll bar, if only the external ScrollView , rather than using ListView scrolling. The following function is required to calculate the current height of the ListView .

public static void Recallistviewheightbasedonchildren (ListView listview) {
if (ListView = = null) return;
ListAdapter listadapter = Listview.getadapter ();
if (ListAdapter = = null) return;
int ntotalheight = 0;
for (int i = 0; i < Listadapter.getcount (); i++) {
View ListItem = Listadapter.getview (i, NULL, ListView);
Listitem.measure (0, 0);
Ntotalheight + = Listitem.getmeasuredheight ();
}

Viewgroup.layoutparams params = Listview.getlayoutparams ();
Params.height = Ntotalheight + (listview.getdividerheight () * (Listadapter.getcount ()-1));
}


PS: For APP security detection Generally I will use:www.ineice.com




Elementary Introduction: The Append method of Android TextView is used in conjunction with scroll bar

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.