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 void Scrolltobottom (final view scroll, final view inner) {Handler Mhandler = new Handler (); Mhandler.post (new Runnable () {public void run () {if (scroll = = NULL | | inner = = NULL) {return;} int offset = 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
Handler.post (New Runnable () { @Override public void Run () { Scrollview.fullscroll (scrollview.focus_down ); }});
Source: http://www.xuebuyuan.com/1587307.html
From for notes (Wiz)
Android control ScrollView Scroll to the bottom