In development, we often need to update the list, and put the list down to the bottom, such as the publication of Weibo, chat interface and so on,
Here are two approaches, the first of which is to use Scrollto ():
Public Static voidScrolltobottom (FinalView Scroll,FinalView Inner) { //how to ask Hovertree.comHandler 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 the 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
// why ask Hovertree.comhandler.post (new Runnable () { @Override public void Run () { scrollview.fullscroll (scrollview.focus_down); } });
Http://www.cnblogs.com/roucheng/p/androidservice.html
Android makes ScrollView scroll to the bottom of the code