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 will find that you cannot scroll to the real bottom because many of the functions on Android are message-based and Message Queuing guarantees synchronization, so function calls are mostly asynchronous operations.
There is a message queue that is asynchronous, the message queue scrolls to the bottom, and the TextView append method is displayed. So I can't scroll to the bottom correctly.
Workaround:
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 scroll bar, prevents the ListView from scrolling, and uses 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 ());
Third, the ListView internal height calculation function
When the ListView is used with a vertical scroll bar, use only external scrollview instead of using the ListView to 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 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