Even if RecyclerView or ViewPager is set on the DrawerLayout, the movement to close the Drawer is prioritized for horizontal scrolling, and the vertical scrolling and Tab switching are pulled by the closing movement, so it cannot be operated comfortably.
With the following settings, you can kill the movement to close the Drawer that occurs when you scroll horizontally on the DrawerLayout. You can also close the Drawer by scrolling horizontally from outside the Drawer.
//In Activity etc. where DrawerLayout is set
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DrawerLayout.DrawerListener drawerListener = new DrawerLayout.DrawerListener() {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
}
@Override
public void onDrawerOpened(View drawerView) {
//Disable side-scrolling on the drawer immediately after opening
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
}
@Override
public void onDrawerClosed(View drawerView) {
//When closed,Enable side-scrolling
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED);
}
@Override
public void onDrawerStateChanged(int newState) {
//There is a change in the state with the drawer open,When the drawer is open again,Disable side-scrolling on the drawer
if (newState == DrawerLayout.STATE_IDLE && mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
}
}
};
mDrawerLayout.addDrawerListener(drawerListener);
mDrawerLayout.setOnTouchListener((v, event) -> {
//When touching the outside of the drawer,Enable side-scrolling
if (mDrawerLayout.isDrawerOpen(Gravity.LEFT) && event.getAction() == MotionEvent.ACTION_DOWN) {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED);
}
return false;
});
}