Set selection to HorizontalScrollView

I have several views in horizontalscrollview, in action (view1, view2, view3 to viewN) for N-views. When I come to this operation, view1 is the first visible element in horizontalscrollview. But I want to start with view5 or view6 to be the first visible element in my horizontalscrollview, so when I scroll left and right, it is displayed as all kinds of view1, view2 to view4 before this view5.

+6
source share
1 answer
horizontalScrollView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { public void onGlobalLayout() { horizontalScrollView.scrollTo(view5.getLeft()); } }); 

This waits until the views are measured, then scrolls to the view5 coordinates.

Did not check it, but it should work.

0
source

All Articles