【问题标题】:Menu drawer to open only with two fingers swipe for DrawerLayout菜单抽屉仅用两根手指滑动即可打开 DrawerLayout
【发布时间】:2014-10-14 08:41:02
【问题描述】:

如何禁用 DrawerLayout 的单指菜单抽屉打开(从左向右滑动),但允许用两根手指滑动打开菜单抽屉?

单指滑动不打开抽屉菜单,但子视图能够处理触摸事件。单指滑动只禁止菜单打开功能。

更新:我已经阅读了这个非常有用的主题:(Android: Difference between onInterceptTouchEvent and dispatchTouchEvent?)。

所以我决定重写方法 onInterceptTouchEvent
public boolean onInterceptTouchEvent(MotionEvent arg) { if (arg.getPointerCount() < 2 && !this.isDrawerOpen(this.listView)) { return true; } else { return super.onInterceptTouchEvent(arg); } }

但显然它不会将触摸事件发送到子视图。 我想我必须使用LOCK_MODE_LOCKED_CLOSED 来控制抽屉的启用/禁用。我稍后会在此处发布该解决方案。

【问题讨论】:

    标签: java android touch swipe drawerlayout


    【解决方案1】:

    我认为这是使用LOCK_MODE 完成此任务的解决方案,如果有人有更好的东西,请分享:

    @Override
    public boolean onInterceptTouchEvent(MotionEvent arg) {
        if (arg.getPointerCount() < 2) {
            if (!this.isDrawerOpen(this.listView)) {
                // The drawer is locked closed. The user may not open it.
                this.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
            }
        } else {
            // The drawer is unlocked.
            this.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
        }
    
        return super.onInterceptTouchEvent(arg);
    }
    

    【讨论】:

      猜你喜欢
      • 2019-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多