Drawerlayout 正在拦截所有触摸事件

Drawerlayout is intercepting all touch events

我的 drawerLayout 正在拦截所有触摸事件。我需要帮助弄清楚如何点击它下面的元素。这是我的 drawerLayout 的设置方式

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/frag_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <RelativeLayout
        .... some code ...

    </RelativeLayout>
</android.support.v4.widget.DrawerLayout>

然后我在另一个像这样的布局中引用这个布局

    <!-- elements inside of this relative layout 
    are unclickable because the drawer layout below 
    intercepts all clicks. If I place the drawer above 
    this view the drawer is beneath all the elements 
    in the relative layout, however, I am able to do 
    my clicks as expected. What I am doing incorrectly? -->

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!-- ... some code * the buttons here are what 
        I want to be clickable when drawer is closed. 
        I currently cannot reach them ... -->

    </RelativeLayout>

 <include layout="@layout/drawer" />

</FrameLayout>

我在抽屉的xml中添加了android:clickable="false"android:focusable="false"。我以编程方式记录了点击次数,它是 id "drawer_layout" 拦截所有点击的实际抽屉。让它不可点击不起作用,它仍然是可点击的。我还尝试将可见性设置为 INVISIBLE 和 GONE,这些也不是可行的解决方案。

如何使 drawerLayout 允许点击它下面的元素?提前致谢!

通过将 clickable 和 focusable 设置为 false,我认为您也会禁用点击布局中的视图。从抽屉布局中删除这些选项。 尝试为抽屉布局内的容器设置 android:clickable="true" 和 android:focusable="true" 。

我想通了。我最终将我的主要布局添加到抽屉中,这与我之前所做的相反,因为在我将抽屉添加到我的主要布局之前。所以我做的改变是

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/frag_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <include layout="@layout/main_layout" />
    </FrameLayout>

    <RelativeLayout
        .... some code ...

    </RelativeLayout>
</android.support.v4.widget.DrawerLayout>

如果其他人遇到这个问题,那就是视图层次结构冲突。您不能将抽屉放在要与之交互的元素之上。如果您有按钮或其他需要与之交互的小部件,则应将其包含在抽屉布局中。我希望这可以帮助其他人。