解决DrawerLayout的不能全屏滑动的问题

用反射,调用下面的方法:
如 setDrawerLeftEdgeSize(this, mDrawerLayout, 0.3f); 但这个比例不宜设置过大。

public static void setDrawerLeftEdgeSize(Activity activity,
DrawerLayout drawerLayout, float displayWidthPercentage) {
if (activity == null || drawerLayout == null)
return;
try {
// find ViewDragHelper and set it accessible
Field leftDraggerField = drawerLayout.getClass().getDeclaredField(
"mLeftDragger");
leftDraggerField.setAccessible(true);
ViewDragHelper leftDragger = (ViewDragHelper) leftDraggerField
.get(drawerLayout);
// find edgesize and set is accessible
Field edgeSizeField = leftDragger.getClass().getDeclaredField(
"mEdgeSize");
edgeSizeField.setAccessible(true);
int edgeSize = edgeSizeField.getInt(leftDragger);
// set new edgesize
// Point displaySize = new Point();
DisplayMetrics dm = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
edgeSizeField.setInt(leftDragger, Math.max(edgeSize,
(int) (dm.widthPixels * displayWidthPercentage)));
} catch (NoSuchFieldException e) {
// ignore
} catch (IllegalArgumentException e) {
// ignore
} catch (IllegalAccessException e) {
// ignore
}
}

虽然没有理解其中的原理,但亲测可用!

你可能感兴趣的:(安卓学习笔记)