【问题标题】:Can't click the buttons behind the DrawerLayout无法点击 DrawerLayout 后面的按钮
【发布时间】:2020-07-21 20:12:22
【问题描述】:

这是我的 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 工作得很好,只是我无法点击它的 后面 ImageButtons。如果我把按钮放在前面,我可以点击它们,但是很好,那么抽屉就被留下了,这是一个可怕的景象。解决这个问题的方法是什么?如何既点击抽屉后面的按钮,又看到前面的抽屉?

提前致谢。

【问题讨论】:

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


    【解决方案1】:

    根据你的布局的Navigation Drawer guideDrawerLayoutshould 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 个孩子的顺序很重要。列表视图应在您的主要内容之后声明,以便在其前面排序(并显示)。

    【讨论】:

    • 嗨,那里。我假设你的意思是你的示例布局中的根元素是&lt;DrawerLayout&gt;。如果我读错了,我深表歉意,但我一直在将此问题用作类似问题的重复目标,而我现在才注意到这一点。
    • 嗨@MikeM。我想你是对的。我最近没有使用过抽屉布局,但据我所知 - 是的,抽屉布局应该是根。谢谢指正。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多