I want to make a view( a button actually) which is inside a scrollview , but when the user scolls down and the button is going up, it moves up only till it reaches the top of the visible screen and then stays there like a fixed header until the user scrolls up again and then it returns to its original position.
I have given the screens for a better understanding.
One way I have solved this is by copying the same view outside the scrollview and keeping it hidden. Only to make it visible when the old button is visisble again.
@Override
public void onScrollChanged(ObservableScrollView scrollView, int x, int y,
int oldx, int oldy) {
Rect scrollBounds = new Rect();
scrollView.getHitRect(scrollBounds);
if (mPriceBtn.getLocalVisibleRect(scrollBounds)) {
// View is within the visible window
mPriceHiddenBtn.setVisibility(View.GONE);
} else {
// View is not within the visible window
//mPriceBtn.setY(y);
mPriceHiddenBtn.setVisibility(View.VISIBLE);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With