my Layout structure is
<LinearLayout>
<TabLayout/>
<Scrollview>
.... other widgets are placed here
</Scrollview>
</LinearLayout>
now the issues is that i have an icon on tablayout. which i want to hide when the scrollview is in normal stage. and when it is scrolled down the icon in tablayout should appear and if scrollview is scrolled top and reaches on top i want to hide the visiblity of the icon on tablayout. How to do it. one way i found that is if somehow i am able to find the top point of scrollview than i can set the visiblity by comparing the the position of scrollview and its topPosition.but i dont know to find the top point of scrollview.
Use below code to detect is scroll view is on top:
mScrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
int scrollY = mScrollView.getScrollY(); //for verticalScrollView
if (scrollY == 0)
//button visible
else
//button invisible
}
});
You can also add some tolerance with changing this line:
if (scrollY == 0)
for something like this (20 px tolerance)
if (scrollY <= 20)