Horiziontal recyclerview on DrawerLayout

余生长醉 提交于 2019-12-03 16:31:00

You should disable intercepting touch event on DrawerLayout when user is scrolling on RecyclerView, So create a custom DrawerLayout like this:

public class DrawerLayoutHorizontalSupport extends DrawerLayout {

    private RecyclerView mRecyclerView;
    private NavigationView mNavigationView;

    public DrawerLayoutHorizontalSupport(Context context) {
        super(context);
    }

    public DrawerLayoutHorizontalSupport(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public DrawerLayoutHorizontalSupport(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (isInside(ev) && isDrawerOpen(mNavigationView))
            return false;
        return super.onInterceptTouchEvent(ev);
    }

    private boolean isInside(MotionEvent ev) { //check whether user touch recylerView or not
        return ev.getX() >= mRecyclerView.getLeft() && ev.getX() <= mRecyclerView.getRight() &&
                ev.getY() >= mRecyclerView.getTop() && ev.getY() <= mRecyclerView.getBottom();
    }

    public void set(NavigationView navigationView, RecyclerView recyclerView) {
        mRecyclerView = recyclerView;
        mNavigationView = navigationView;
    }


}

And after inflating your layout just call set and pass your NavigationView and RecyclerView.

In onInterceptTouchEvent i check whether drawer is open and user touch inside RecyclerView then I return false so DrawerLayout do nothing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!