像Google Play商店应用一样的嵌套RecyclerView [英] Nested RecyclerView like Google Play Store App

查看:104
本文介绍了像Google Play商店应用一样的嵌套RecyclerView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在复制在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商店应用:

推荐答案

这是 github存储库.

Here's a tutorial for implementing such RecyclerView. You might also consider looking at the github repository as well.

该想法是在触摸内部RecyclerView时禁用外部RecyclerView的触摸检测.参见实现RecyclerView适配器类中的"noreferrer>此处.

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);

这篇关于像Google Play商店应用一样的嵌套RecyclerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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