我drawerlayout设置在左边,但是总是要很靠近屏幕左边才能滑出来,有没有什么方法可以加大滑 30
我drawerlayout设置在左边,但是总是要很靠近屏幕左边才能滑出来,有没有什么方法可以加大滑动反应区域...
我drawerlayout设置在左边,但是总是要很靠近屏幕左边才能滑出来,有没有什么方法可以加大滑动反应区域
展开
1个回答
展开全部
/**
* 抽屉滑动范围控制
* @param activity
* @param drawerLayout
* @param displayWidthPercentage 占全屏的份额0~1
*/
private 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) {
Log.e("NoSuchFieldException", e.getMessage().toString());
} catch (IllegalArgumentException e) {
Log.e("IllegalArgument", e.getMessage().toString());
} catch (IllegalAccessException e) {
Log.e("IllegalAccessException", e.getMessage().toString());
}
}
这个方法可以解决
* 抽屉滑动范围控制
* @param activity
* @param drawerLayout
* @param displayWidthPercentage 占全屏的份额0~1
*/
private 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) {
Log.e("NoSuchFieldException", e.getMessage().toString());
} catch (IllegalArgumentException e) {
Log.e("IllegalArgument", e.getMessage().toString());
} catch (IllegalAccessException e) {
Log.e("IllegalAccessException", e.getMessage().toString());
}
}
这个方法可以解决
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询