导航抽屉布局与主布局重叠

时间:2015-08-17 02:55:36

标签: android

如何让我的主要布局直接排列在DrawerLayout下面?我的主要布局如下所示,主要由列表视图组成。现在一切都重叠了。所以下面首先显示我的DrawerLayout。关闭DrawerLayout后,列出了我的主要活动。

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


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/container_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />
    </LinearLayout>

    <FrameLayout
        android:id="@+id/container_body"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
</LinearLayout>


    <fragment
    android:id="@+id/fragment_navigation_drawer"
    android:name=“com.example.my.app.FragmentDrawer"
    android:layout_width="@dimen/nav_drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:layout="@layout/fragment_navigation_drawer"
    tools:layout="@layout/fragment_navigation_drawer" />

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





<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent”
android:orientation="vertical">


<TextView
    android:id="@+id/txt_empty_list_cars"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_margin="4dp"
    android:gravity="center"
    android:text="@string/view1"
    android:textAppearance="?android:attr/textAppearance"
    android:textColor="@android:color/darker_gray"
    android:visibility="gone" />

<ListView
    android:id="@+id/list_cars"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/txt_header"
    android:layout_margin="4dp"
    android:divider="@android:drawable/divider_horizontal_bright"
    android:dividerHeight="0.5dp"
    android:listSelector="@android:drawable/list_selector_background" />

3 个答案:

答案 0 :(得分:1)

因此,您的问题drawer layout与下面的linear layout重叠。使用

android: layout_below="@id/drawer_layout" 

linear layout中。这将线性排列两种布局。

答案 1 :(得分:0)

为了正确使用DrawerLayout,它必须是整个布局的唯一根/父视图。

<android.support.v4.widget.DrawerLayout> 

      /*other nested child views */

      <fragment
      android:id="@+id/fragment_navigation_drawer"
      ... 
      />    

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

另外,为防止重叠,请确保根据设计指南有两个直接子视图 https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html

&#34;要使用DrawerLayout,请将主要内容视图定位为宽度和高度为match_parent的第一个子视图。在主内容视图后添加抽屉作为子视图并设置 layout_gravity恰当。&#34;

答案 2 :(得分:0)

我不知道你是否正在寻找像新的gmail应用程序一样的滑动面板 但如果是,你可以自己引用Sliding Pane Layout,这非常棒tutorial

希望它有所帮助,快乐的编码。