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