Android control ScrollView Scroll to the bottom

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.