Search code examples
androidvisibilityhorizontalscrollviewchildviews

How to set a particular child of horizontal scrollView as first visible child: Android


I have 6 items/views in a horizontal scrollView, in an activity. {view1, view2, view3, view4, view5, view6} When i come to this activity, view1 is the the first visible item in the scrollview. But I would like to have view1, hidden and view2 to be the first to be visible. I still want it as a part of my scrollview items, so when i swipe left to right, it shows up as the first item.

Could someone please help me with this, so that I can get android to render the Horizontalscrollview such that first item visible is view2?

Thanks, Sunny


Solution

  • you will need to auto scroll it to the second position at rendering time. something like this-

    // let x is distance , you want. you can scroll it like
                horiScrollView.scrollBy(-x, 0);