tim blue
tim blue

Reputation: 138

Scroll View doesn't scroll to top - Android

I am trying to scroll to the top of my ScrollView, and I am using the below and both types it works a little over 50% the other time sit just stays where it is

private void focusOnView(){
    new Handler().post(new Runnable() {
        @Override
        public void run() {
            sv.scrollTo(0, sv.getTop());
        }
    });
}

And the other way I am doing it

sv.post(new Runnable() {
        public void run() {
            Log.i(TAG, "TOP TOP");
            sv.scrollTo(0, sv.getTop());
        }
    });

THnaks for the help

Upvotes: 1

Views: 183

Answers (2)

Ken
Ken

Reputation: 1393

Another approach:

sv.post(new Runnable() {
    public void run() {
        sv.fullScroll(ScrollView.FOCUS_UP);
    }
});

If you want to scroll to bottom, using FOCUS_DOWN.

Upvotes: 0

N J
N J

Reputation: 27505

Use this

sv.post(new Runnable() {
        public void run() {
            Log.i(TAG, "TOP TOP");
            sv.scrollTo(0, 0);
        }
    });

Upvotes: 3

Related Questions