我想在右侧滑动打开导航视图,无论右侧滑动在哪里。默认情况下,您必须在侧面完全向右滑动,但是例如,我想从中间滑动以打开Navigationview

最佳答案

您可以使用类似以下的方法增加抽屉的滑动边缘

public static void increaseSwipeEdgeOfDrawer(DrawerLayout mDlSearchDrawer) {
        try {

            Field mDragger = mDlSearchDrawer.getClass().getDeclaredField(
                    "mRightDragger");//mRightDragger or mLeftDragger based on Drawer Gravity
            mDragger.setAccessible(true);
            ViewDragHelper draggerObj = (ViewDragHelper) mDragger
                    .get(mDlSearchDrawer);

            Field mEdgeSize = draggerObj.getClass().getDeclaredField(
                    "mEdgeSize");
            mEdgeSize.setAccessible(true);
            int edge = mEdgeSize.getInt(draggerObj);


            mEdgeSize.setInt(draggerObj, <size of the edge here>);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


或者您可以在顶部保留与抽屉布局大小匹配的视图,在其上分配强听者以检测滑动并在其上调用DrawerLayout#openDrawer(android.view.View)

10-06 16:21