Surbhi Kartpay
Surbhi Kartpay

Reputation: 31

How can I set visibily gone on scrolling downwards?

I have kept a button in my scroll view which should be visible only when I am scrolling up and should get invisible as I scroll down like in paytm. It is a simple scroll view inside a fragment.

      scrollBtn.setVisibility(View.GONE);

    scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
        @Override
        public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            scroll.setVisibility(View.VISIBLE);

        }
    });

    scrollBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            scrollView.scrollTo(0, 0);
        }
    });

Upvotes: 1

Views: 93

Answers (2)

Juanjo Berenguer
Juanjo Berenguer

Reputation: 789

This should help you.

Code

scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
           @Override
           public void onScrollChange(View view, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
               //Scrolling down
               if(scrollY<oldScrollY){
                   scrollBtn.setVisibility(View.GONE);
               }else{
                   scrollBtn.setVisibility(View.VISIBLE);
               }
           }
       });

Upvotes: 1

hossam scott
hossam scott

Reputation: 466

check out this one Detecting the scrolling direction in the adapter (up/down) and inside mIsScrollingUp = false;

use your code to hide the layout u need

Upvotes: 0

Related Questions