user2138983
user2138983

Reputation: 1333

Add Fixed button inside scrollview which is visible even when scrolling

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

Upvotes: 8

Views: 2712

Answers (2)

user2138983
user2138983

Reputation: 1333

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



}

Upvotes: 6

npace
npace

Reputation: 4258

Check out this tutorial. It's about an ActionBar with similar behavior, made by ome of Google's own Android devs. I'm guessing you can find most of what you need there.

Upvotes: 0

Related Questions