无法点击DrawerLayout后面的按钮

4

以下是我的 XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Main"
android:background="@android:color/black" >

  <RelativeLayout
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageButton
        android:id="@+id/calendar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/about"
        android:layout_centerHorizontal="true"
        android:background="@drawable/calendar" />

    <ImageButton
        android:id="@+id/okan"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/calendar"
        android:layout_marginLeft="20dp"
        android:layout_toRightOf="@+id/calendar"
        android:background="@drawable/okanliyiz"/>

    <ImageButton
        android:id="@+id/about"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="20dp"
        android:layout_marginTop="140dp"
        android:layout_toLeftOf="@+id/calendar"
        android:background="@drawable/info" />

</RelativeLayout>

<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false" >

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="false" />

<ListView
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:background="#111"/>
</android.support.v4.widget.DrawerLayout>


</RelativeLayout>

我编写了程序部分,Drawer 已经可以正常工作,但是我无法点击它后面的ImageButton。如果我把按钮放在前面,我就能够点击它们,但是抽屉就会被遮挡,这样看起来很糟糕。有什么解决方法吗?我怎样才能既点击抽屉后面的按钮又能看到抽屉在前面?
谢谢您提前的帮助。
1个回答

11
根据导航抽屉指南DrawerLayout应该是您布局的根元素。它应该只有两个子元素——一个包含您的“主内容”——按钮、文本字段等,另一个应该是抽屉本身的内容。像这样:
<android.support.v4.widget.DrawerLayout>

    <RelativeLayout>
        <Button/>
        <EditText/>
    </RelativeLayout>

    <ListView android:id="@+id/drawer_list" />

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

此外: 由于DrawerLayout(一个ViewGroup)的Z-order,两个子元素的顺序非常重要。列表视图应在主内容之后声明,以便它在其前面排序(并显示)。

1
你好。我猜你在示例布局中的根元素应该是<DrawerLayout>。如果我理解有误,那么请原谅,但我一直将这个问题用作类似问题的重复目标,并且刚刚才注意到这一点。 - Mike M.
1
嗨@MikeM。我认为你是对的。最近我没有使用过抽屉布局,但就我记得而言,是的,抽屉布局应该是根布局。感谢您的纠正。 - stan0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接