使用Google设计库如何隐藏向下滚动上的FAB按钮? [英] Using Google Design Library how to hide FAB button on Scroll down?
问题描述
Google已发布设计库,我正在使用
Google have released Design library, I am using
compile 'com.android.support:design:22.2.1'
但是,我看不到任何有关如何使用此库以及如何在滚动上为FAB
条设置动画的代码示例.我想我可以监听ListView
上的滚动事件,然后自己为按钮设置动画,但这不是API所固有的(这不是此支持库的重点).
However I cant see any code examples of how to use this library and how to animate the FAB
bar on scroll. I guess I can listen for scroll events on the ListView
and then animate the button myself, but is this not baked into the API (is this not the point of this support library).
有例子吗?
推荐答案
如果您使用的是RecyclerView
,并且正在寻找简单的方法,则可以尝试以下操作:
If you're using RecyclerView
and you're looking for something simple, you can try this:
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener(){
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy){
if (dy > 0)
fabAddNew.hide();
else if (dy < 0)
fabAddNew.show();
}
});
通过用常量替换0
,您可以调整触发的灵敏度,从而提供更流畅的体验
By replacing 0
with a constant, you can adjust the sensitivity of triggering, providing smoother experience
这篇关于使用Google设计库如何隐藏向下滚动上的FAB按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!