culebrins
culebrins

Reputation: 448

HorizontalScrollView - auto scroll to a selected view

I have a HorizontalScrollView, inside the horizontal I have a linearlayout (orientation=horizontal) with 10 views.

I'm trying to show the horizontalscrollview auto scrolled to a selected view.

I've done this requesting focus from the selected view:

li.setFocusable(true);

The problem is that the view apperas at the right of the screen and I'm trying to show the view centered.

Any idea?

Thanks

Upvotes: 2

Views: 1194

Answers (1)

handrenliang
handrenliang

Reputation: 1047

You can use smoothScrollTo(int x, int y) method, (x, y) represents the position of selected view, you can calculate it easily: (View.getLeft() + View.getPaddingLeft(), View.getTop()).

Upvotes: 3

Related Questions