Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Fixed button inside scrollview which is visible even when scrolling

Tags:

android

enter image description hereI 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.

enter image description here

like image 203
user2138983 Avatar asked Jun 04 '13 07:06

user2138983


1 Answers

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);
    }



}
like image 84
user2138983 Avatar answered Oct 17 '22 05:10

user2138983