Hide FAB in NestedScrollView when scrolling

后端 未结 4 1431
误落风尘
误落风尘 2021-02-07 14:06

I am having a nestedscrollview with content like some linearlayouts and textviews. I am using a floatingactionbutton library for some reasons, as well. So I can\'t use any behav

4条回答
  •  情深已故
    2021-02-07 14:24

    define variable type int in your Activity or fragment to set previous Scroll from ScrollView then use this method to listen change scroll in ScrollView Class

     scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
            @Override
            public void onScrollChanged() {
    
        // previousScrollY this variable is define in your Activity or Fragment
                if (scrollView.getScrollY() > previousScrollY && floatingActionButton.getVisibility() == View.VISIBLE) {
                    floatingActionButton.hide();
                } else if (scrollView.getScrollY() < previousScrollY && floatingActionButton.getVisibility() != View.VISIBLE) {
                    floatingActionButton.show();
                }
                previousScrollY = scrollView.getScrollY();
            }
        });
    

    will work done all version of android

提交回复
热议问题