[英]close Navigation Drawer with no animation
I am trying to close my navigation drawer after I finish certain activities immediately, without the sliding animation. 我试图在完成某些活动后立即关闭导航抽屉,而没有滑动动画。 I don't close it on activity start because I would like it to stay open if the user backs out of the activity.
我不会在活动开始时关闭它,因为如果用户退出活动,我希望它保持打开状态。 However, I cannot get it to close without a brief flickering animation as it closes itself.
但是,我无法在没有短暂闪烁的动画的情况下关闭它,因为它本身会关闭。 I have tried variations of the following code:
我尝试了以下代码的变体:
protected void closeDrawerImmediate() {
mDrawerLayout.setVisibility(View.GONE);
mDrawerLayout.closeDrawers();
mDrawerLayout.setX(0);
mDrawerLayout.setVisibility(View.VISIBLE);
}
You can use the new DrawerLayout.closeDrawer(int/View, bool)
methods in v24 of the support library to instantly close a drawer: 您可以在支持库的
DrawerLayout.closeDrawer(int/View, bool)
使用新的DrawerLayout.closeDrawer(int/View, bool)
方法立即关闭抽屉:
drawerLayout.closeDrawer(Gravity.LEFT, false);
If you just want to close a drawer immediately, such as when you're launching an activity from tapping on a drawer item, that is probably enough. 如果您只想立即关闭抽屉,例如在通过点击抽屉项目启动活动时,这可能就足够了。
If you want to close the drawer on coming back to the activity, I'd set a stateful boolean like closeDrawerOnResume = true
wherever is appropriate (eg. starting a new activity), and then in onResume
check this boolean and close the drawer without animating if it is true. 如果您想在返回活动时关闭抽屉,我会在适当的地方设置一个有状态的布尔值,如
closeDrawerOnResume = true
(例如,开始一个新的活动),然后在onResume
检查此布尔值并关闭抽屉而不进行动画处理如果是真的。
You can consider setting animation time to 0. But it seems it's not as easy as setting one property. 您可以考虑将动画时间设置为0。但是,这似乎不如设置一个属性那么容易。 Here is tutorial and the code but it requires importing sources for
DrawerLayout
and ViewDragHelper
into project and small modifications there. 这是教程和代码,但是需要将
DrawerLayout
和ViewDragHelper
源导入项目并进行少量修改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.