如何设置向下滚动的可见性?

时间:2018-09-05 09:40:38

标签: android scroll scrollview

我在滚动视图中保留了一个按钮,该按钮仅在向上滚动时才可见,而在向下滚动时(如在paytm中)应该不可见。这是片段内的简单滚动视图。

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

2 个答案:

答案 0 :(得分:1)

这应该对您有帮助。

代码

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

答案 1 :(得分:0)

检出此Detecting the scrolling direction in the adapter (up/down)和内部mIsScrollingUp = false;

使用您的代码隐藏所需的布局