Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio automatic scroll to bottom when ScrollView expands?

Tags:

android

Is it possible to make my ScrollView automaically scroll to the bottom if the height expands? For example, if a Checkbox is checked and some views are then added to the ScrollView, they will be "below the current focus" and it might appear as if they were not added.

like image 518
Simon Andersson Avatar asked Feb 14 '17 13:02

Simon Andersson


2 Answers

For automatically scrolling to add the code:

final ScrollView scrollview = ((ScrollView) findViewById(R.id.scrollview));
scrollview.post(new Runnable() {
    @Override
    public void run() {
        scrollview.fullScroll(ScrollView.FOCUS_DOWN);
    }
});
like image 156
Vlad Ivchenko Avatar answered Nov 08 '22 19:11

Vlad Ivchenko


Runnable runnable=new Runnable() {
        @Override
        public void run() {
            scrollView.fullScroll(ScrollView.FOCUS_DOWN);
        }
    };
    scrollView.post(runnable);

call this lines every time after adding your view to your layout. That will lead you to initialize Runnable object once.

like image 20
Ramzy Hassan Avatar answered Nov 08 '22 18:11

Ramzy Hassan