无法单击DrawerLayout后面的按钮

时间:2014-03-07 13:44:24

标签: android android-layout imagebutton navigation-drawer drawerlayout

这是我的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 个答案:

答案 0 :(得分:8)

根据您布局的Navigation Drawer guide DrawerLayout should be the root。它应该只有只有2个孩子 - 一个包含你的“主要内容” - 按钮,文本字段等。另一个应该是抽屉本身的内容。像这样:

<android.support.v4.widget.DrawerLayout>

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

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

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

另外: 由于DrawerLayout(它是ViewGroup)的 Z-order ,2个孩子的顺序很重要。列表视图应在主要内容之后声明,以便在其前面进行排序(和显示)。