滚动时在NestedScrollView中隐藏FAB [英] Hide FAB in NestedScrollView when scrolling

查看:79
本文介绍了滚动时在NestedScrollView中隐藏FAB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个nestedscrollview,其内容类似于一些linearlayouts和textviews. 由于某些原因,我也正在使用floatactionbutton库.所以我不能使用任何行为. 我不知道应该如何处理scrollview的scrollchangelistener来像行为一样动态隐藏和显示fab.

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 behavior for it. I don't know how I should handle the scrollchangelistener from scrollview to hide and show the fab dynamically like a behavior.

有人建议如何在滚动时隐藏和显示晶圆厂吗?

Any suggestions how to hide and show the fab while scrolling?

推荐答案

简单地将下面的代码添加到NestedScrollView ScrollChangeListener中:

Simple add this code below to your NestedScrollView ScrollChangeListener:

NestedScrollView nsv = v.findViewById(R.id.nsv);
    nsv.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
        @Override
        public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            if (scrollY > oldScrollY) {
                fab.hide();
            } else {
                fab.show();
            }
        }
    });

这篇关于滚动时在NestedScrollView中隐藏FAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆