Here are two approaches, the first of which is to use Scrollto ():
UblicStatic voidScrolltobottom (Final view scroll, final view inner) {Handler Mhandler=NewHandler (); Mhandler.post (NewRunnable () { Public voidrun () {if(Scroll = =NULL|| Inner = =NULL) {return;}intoffset = inner.getmeasuredheight ()-scroll.getheight ();if(Offset <0) {offset=0; } Scroll.scrollto (0, offset); } });}
The first implementation is relatively cumbersome, it is recommended to use the second method, using Fullscrol ()
Let's take a look at this function:
Scrollview.fullscroll (scrollview.focus_down); Scroll to bottom scrollview.fullscroll (scrollview.focus_up); scroll to top
It is important to note that the method cannot be called directly
Because many of the Android functions are synchronized based on Message Queuing, an action is required,
After AddView, not equal to the immediate display, but in the queue to wait for processing, although soon, but if the call fullscroll immediately, the view may not be displayed, so it will fail
Should be updated in the new thread via handler
Handler.post (new Runnable () { @Override publicvoid run () { Scrollview.fullscroll (Scrollview.focus_down); }});
Android control ScrollView Scroll to the bottom