如何在滚动的Recycler视图上与协调器父级一起显示/隐藏FAB [英] how to show/hide FAB on scroll Recycler view with coordinator parent
问题描述
我有一个带有协调器布局的活动.内部活动中有一个带有Recycler视图和浮动按钮的片段.当滚动Recycler视图时如何显示/隐藏浮动按钮并避免使用fab行为?!
I have an activity with coordinator layout.inside activity there is a fragment with Recycler view and float button.how can I show/hide float button when Scroll Recycler view and avoid to use fab behavior?!
在活动布局中: CoordinatorLayout -----> AppBarLayout ---->工具栏和FrameLayout以及底部栏视图
in activity layout: CoordinatorLayout----->AppBarLayout---->Toolbar and FrameLayout and Bottom bar view
在片段布局中: RelativeLayout ---->回收站视图和浮动按钮
in fragment layout: RelativeLayout---->Recycler view and float button
我想实现Google+主页之类的功能. 我该如何实现这种情况?
I want to implement something like Google+ home page. how can I implement this scenario?
在我的片段中通过接口使用活动的协调器布局,并使用fab行为显示/隐藏fab ...直到找到更好的解决方案!!!
using coordinator layout of activity by interface in my fragment and show/hide fab with fab behavior ... until I find better solution!!!
推荐答案
此代码可以正常工作:
mRecycler.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if(dy > 0){
mFab.hide();
} else{
mFab.show();
}
super.onScrolled(recyclerView, dx, dy);
}
});
您不能这样做:
app:layout_anchor="@id/listView"
app:layout_anchorGravity="bottom|end"
在此处中查找:
不支持CoordinatorLayout内置的支持 根据此Google帖子的ListView.
There is no support built-in for CoordinatorLayout to work with ListView according to this Google post.
这篇关于如何在滚动的Recycler视图上与协调器父级一起显示/隐藏FAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!