user2529345
user2529345

Reputation: 13

How to Center Scroll Bar in HorizontalScrollView Android

The question is pretty much self explanatory but I was wondering how to see the center part of the HorizontalScrollView when it first appears on the screen. It would display exactly as if you had scrolled to the center of the view.

So far I have tried:

scrollView.scrollTo(x, y);

Where 'y' has been 0 and 'x' has been half the width of the contents of scrollView.

Any help would be greatly appreciated

Thanks,

Evan

Upvotes: 1

Views: 90

Answers (1)

Zoran
Zoran

Reputation: 1494

You have to use:

scrollView.post(new Runnable() {
    @Override
    public void run() {
        scrollView.scrollTo(x, y);
    }
});

Upvotes: 1

Related Questions