Android 滑块抽屉占据整个屏幕

Android 滑块抽屉占据整个屏幕,android,xml,android-layout,menu,slider,Android,Xml,Android Layout,Menu,Slider,我创建了一个自定义滑动菜单,但它似乎占据了整个屏幕。我的意思是我不能点击版面上的其他项目。它并不总是打开的,它只是实际上禁用了它“下”的所有项目。我已附加了一个活动的xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="matc

我创建了一个自定义滑动菜单,但它似乎占据了整个屏幕。我的意思是我不能点击版面上的其他项目。它并不总是打开的,它只是实际上禁用了它“下”的所有项目。我已附加了一个活动的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"
    android:gravity="bottom"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".HomeActivity">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="132dp"
        android:text="@string/name"
        android:textSize="25sp" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/textView1"
        android:layout_alignParentLeft="true"
        android:contentDescription="@string/description1"
        android:src="@drawable/fam" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="@string/enter" />

    <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/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="#666"
        android:dividerHeight="1dp"
        android:background="#333"
        android:paddingLeft="15sp"
        android:paddingRight="15sp" />

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

</RelativeLayout>

尝试此选项,而不是匹配父项:

android:layout_height="wrap_content"

请改变宽度

   <ListView android:id="@+id/left_drawer"
        android:layout_width="match_parent"//not indp
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="#666"
        android:dividerHeight="1dp"
        android:background="#333"
        android:paddingLeft="15sp"
        android:paddingRight="15sp"
        />

抽屉应该是所有视图的父视图,请尝试此操作

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".HomeActivity" >


    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="132dp"
        android:text="@string/name"
        android:textSize="25sp" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/textView1"
        android:layout_alignParentLeft="true"
        android:contentDescription="@string/description1"
        android:src="@drawable/fam" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="@string/enter" />
</RelativeLayout>

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

  <ListView android:id="@+id/left_drawer"
        android:layout_width="match_parent"//not indp
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="#666"
        android:dividerHeight="1dp"
        android:background="#333"
        android:paddingLeft="15sp"
        android:paddingRight="15sp"
        />

只需将下面的
android:layout_=“@+id/button1”
设置到您的
抽屉布局,如下所示:

  <android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:layout_below="@+id/button1"> //set your drawer layout at the bottom of your `Button`. 
//在“按钮”底部设置抽屉布局。

请查看有关Android开发者抽屉布局的培训文章-

从我的观点来看,你似乎用得不对。正如上面文章中所述:以下布局使用具有两个子视图的抽屉布局:包含主要内容的框架布局(在运行时由片段填充),以及导航抽屉的列表视图。

此框架布局用于活动内容。所以你必须使用碎片


这个列表视图是导航抽屉的内容



因此,将其他组件放入片段中。

我也有同样的问题,下面的代码对我有效。使用它而不是匹配父项: android:layout\u height=“包装内容”


我的代码中有这个功能。我把安卓:layout\u height=“wrap\u content”放进去,删除了marginTop,我有了全高的滑动抽屉。

把它的高度
android:layout\u height=“match\u parent”
改成
android:layou height=“wrap\u content”
。另外,给你的问题贴一张截图。不,现在连开始都没有了,Logcat给我一个
E/AndroidRuntime(1275):java.lang.IllegalArgumentException:DrumerLayout必须使用MeasureSpec.精确测量。
更改了宽度,其工作原理与以前相同。谢谢你!
<FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
<ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="#666"
        android:dividerHeight="1dp"
        android:background="#333"
        android:paddingLeft="15sp"
        android:paddingRight="15sp"
        />
    android:layout_marginTop="200dp"