嵌套 RecyclerView 就像 Google Play 商店应用 [英] Nested RecyclerView like Google Play Store App
问题描述
我目前正在努力复制在 Play 商店应用中实现的 UI 模式.为了实现这样的行为,我使用了一个 Vertical RecyclerView
作为外部视图,并在外部 Vertical RecyclerView
的适配器内添加了一个水平的 RecyclerView
.
I am currently working on replicating the UI pattern implemented in the Play Store App. For implementing such a behavior, I have used a Vertical RecyclerView
as outer view and added a horizontal RecyclerView
inside the adapter of the outer Vertical RecyclerView
.
我目前面临的问题是当外部 RecyclerView
滚动时,内部水平 RecyclerView
无法捕捉到滚动事件,但是当外部 RecyclerView
不滚动,我们可以平滑滚动水平RecyclerView
.
The problem I am currently facing is while the outer RecyclerView
is scrolling, the inner horizontal RecyclerView
cannot catch the scroll event on it, but when the outer RecyclerView
is not scrolling, we can scroll the horizontal RecyclerView
smoothly.
如果有人可以提供帮助,请留下您的评论.Cou 可以在 Play 商店中测试该功能,它启用内部水平 RecyclerView
的滚动,即使外部 RecyclerView
正在滚动.
If any one can be helpful please leave your comment. Cou can test the functionality in the Play store it enables the scroll of inner horizontal RecyclerView
, even if the outer RecyclerView
is scrolling.
Play 商店应用:
推荐答案
这里是 一个教程来实现这样的RecyclerView
.您也可以考虑查看 github 存储库.
Here's a tutorial for implementing such RecyclerView
. You might also consider looking at the github repository as well.
这个想法是在触摸内部 RecyclerView
时禁用外部 RecyclerView
的触摸检测.见实现 此处 在父 RecyclerView
适配器类中.
The idea is to disable the touch detection of the outer RecyclerView
when the inner RecyclerView
is touched. See the implementation here in the parent RecyclerView
adapter class.
// Disable touch detection for parent recyclerView if we use vertical nested recyclerViews
private View.OnTouchListener mTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
};
然后将触摸侦听器设置为视图.
And then set the touch listener to the view.
view.findViewById(R.id.recyclerView).setOnTouchListener(mTouchListener);
这篇关于嵌套 RecyclerView 就像 Google Play 商店应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!