问题描述
我是使用新的导航抽屉在我的应用程序。这是伟大的,除了我还没有找到一种简单的方法,以设置抽屉是打开的。默认行为是从屏幕打开的左边缘的阻力。这是罚款,除非手机/表中有一个案例上和电话的边缘不能触及。我想允许用户从屏幕的左边的余量触摸和拖动。这是很容易设置与其他导航抽屉库(滑动LIB)。我还没有看到与谷歌的lib不幸的是什么。
I am using the new Navigation Drawer in my app. It is great except I have not found an easy way to set how the drawer is open. The default behavior is drag from the left edge of the screen to open. This is fine, unless the phone/table has a case on and the edge of phone can not be touched. I would like to allow the user to touch and drag from a margin of the screen to the left. This is easy to set with other nav drawer libs(Sliding lib). I have not seen anything with Google's lib unfortunately.
有一个的onTouchEvent()方法,可能可以使用NavigationLayout。当然,你可以听所有的触摸事件,并引发openDrawer,而是希望一个简单的方法用更少的code。任何想法?
There is an onTouchEvent() method for the NavigationLayout that could may be used. Of course you could listen to all touch events and trigger an openDrawer, but was hoping for an easy way with less code. Any ideas?
推荐答案
在这里,我通过思考找到了解决办法
Here I've found a solution via reflections
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
Field mDragger = mDrawerLayout.getClass().getDeclaredField(
"mLeftDragger");//mRightDragger for right obviously
mDragger.setAccessible(true);
ViewDragHelper draggerObj = (ViewDragHelper) mDragger
.get(mDrawerLayout);
Field mEdgeSize = draggerObj.getClass().getDeclaredField(
"mEdgeSize");
mEdgeSize.setAccessible(true);
int edge = mEdgeSize.getInt(draggerObj);
mEdgeSize.setInt(draggerObj, edge * 5); //optimal value as for me, you may set any constant in dp
这篇关于设置拖累利润率为Android导航抽屉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!