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

Source: Internet
Author: User

One, on Android, a single textview is not scrollable and needs to be placed in a scrollview. ScrollView provides a series of functions where Fullscroll is used to implement FOCUS_UP and Focus_down keys, that is, scrolling to the top and bottom.   If you call Fullscroll immediately after TextView append, you'll find that you can't scroll to the bottom, because many of the functions on Android are message-based and Message Queuing guarantees synchronization, so function calls are mostly asynchronous operations.   Message Queuing is asynchronous, Message Queuing scrolls to the bottom and then TextView's Append method is displayed. So I can't scroll to the bottom correctly.   Solutions:final scrollview scrollview =  (ScrollView) Findviewbyid (r.id.scrollview1);        if  (scrollview != null)  {            scrollview.post (new runnable ()  {                 public void run ()  {                     scrollview.fullscroll (Scrollview.focus_down);                 }       });         the ListView is used with the scrollbar to prevent the ListView from scrolling, Use the scroll bar to scroll to the bottom of the ListView to change the sentence in the above code run to this Scrollview.scrollto (0, mlistviewlist.getheight ());  three, ListView Internal Height Calculation function when the ListView is used with the vertical scroll bar, use only external scrollview instead of the ListView scroll. 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&nbSp;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.