禁用DrawerLayout的稀松触摸手势 [英] Disable DrawerLayout's scrim touch gesture

查看:179
本文介绍了禁用DrawerLayout的稀松触摸手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要禁用稀松布上的触摸手势(红色突出显示的部分).我只想通过滑动来解开抽屉.

I need to disable touch gesture on the scrim (the red highlighted part). I want to dismiss the drawer only with the swipe.

问题是,当抽屉布局打开并且我需要从红色突出显示部分下方的ListView中选择一个元素时,发生的事情是抽屉已关闭,只有在这一点上,我才能从ListView中选择一个元素

The issue is that when the drawer layout is open and I need to select an element from the ListView below the red highlighted part, what's happend is that the drawer get closed and only at this point I can select an element from the ListView.

打开抽屉时,我还需要直接从ListView中选择元素

I need to select the element from the ListView directly, also when the Drawer is opened

推荐答案

您必须为此创建自定义抽屉

You have to create custom drawer for that like this

public class CustomDrawer extends DrawerLayout {



    public CustomDrawer(Context context) {
        super(context);

    }

    public CustomDrawer(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

    }

    public CustomDrawer(Context context, AttributeSet attrs) {
        super(context, attrs);

    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        if(isDrawerOpen(Gravity.START)){
            if(event.getX() > getChildAt(1).getWidth()){
                return false;
            }
        }
        return super.onInterceptTouchEvent(event);
    }

}

注意:getChildAt(1)应该是您赋予重力开始"并且宽度决定打开抽屉宽度的那个孩子.

Note : getChildAt(1) should be that child to whom you have given gravity as "start" and whose width determines the width of opening drawer.

我希望这可以解决您的问题

I hope this should solve your problem

这篇关于禁用DrawerLayout的稀松触摸手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆