You need to create custom DrawerLayout and @overide onInterceptTouchEvent
. Then you can create some method for registering drawer views (like setDrawerViewWithoutIntercepting
), for which will be possible to use (click) main content, when are open. You should call this method in your activity/fragment, where is this DrawerLayout used.
OnInterceptTouchEvent will be returning false just in case registered drawer view is opened and touches are outside of drawer view area. This means all functionality remains the same (like closing drawer view using swiping, etc.)
This is just example which should be improved, so I hope it will help you.
private View currentDrawerView;
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
boolean result = super.onInterceptTouchEvent(event);
if (currentDrawerView != null && isDrawerOpen(currentDrawerView)) {
DrawerLayout.LayoutParams layoutParams = (DrawerLayout.LayoutParams) currentDrawerView.getLayoutParams();
if (layoutParams.gravity == Gravity.RIGHT) {
if (event.getX() < currentDrawerView.getX()) {
result = false;
}
}
else if (layoutParams.gravity == Gravity.LEFT) {
if (event.getX() > currentDrawerView.getX() + currentDrawerView.getWidth()) {
result = false;
}
}
// ......
};
return result;
}
public void setDrawerViewWithoutIntercepting(View view) {
this.currentDrawerView = view;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…