Android ScrollView Scroll to Bottom

2019-09-09 07:52发布

问题:

The ScrollView in Android is really confusing. I'm working on an app that adds a fragment of text to a TextView inside the ScrollView, and I want it to scroll to the bottom of the ScrollView.

I've tried these ways:

Scroll1.fullScroll(View.FOCUS_DOWN);

Scroll1.scrollTo(0, sv.getBottom());

Scroll1.scrollTo(0, Scroll1.getY() + Scroll1.getHeight());

NOTE: 1. Scroll1 is the ScrollView I used. 2. The first two methods can't scroll to the bottom. The last just doesn't work.

How can I achieve this? Please help. Thanks.

回答1:

try this it may helps if I know your problem: paste it in scroll view in xml

android:fillViewport="true"

OR

in java activity

scrollView.setFillViewport(true);


回答2:

use the following code once you want to update the scrollview:

scrollView.post(new Runnable() { 
     public void run() {
         scrollView.fullScroll(View.FOCUS_DOWN);
     }
 });