如何在抽屉布局上方添加视图?

时间:2013-12-23 09:33:48

标签: android android-layout android-fragments fragment

http://developer.android.com/design/patterns/navigation-drawer.html

我正在做导航抽屉。代码建议我使用这样的导航抽屉:

<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">
    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <!-- The navigation drawer -->
    <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>

framelayout会存储片段而left_drawer是左侧菜单,问题是,我想在left_drawer和framelayout之间添加一个视图,这是

left_drawer on top of my view , my view on top of framelayout。如何实现这样的布局?或者我需要将我的视图添加到每个片段?

由于

更新:

<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" >

    <!--
         As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions.
    -->

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

    <!--
         android:layout_gravity="start" tells DrawerLayout to treat
         this as a sliding drawer on the left side for left-to-right
         languages and on the right side for right-to-left languages.
         The drawer is given a fixed width in dp and extends the full height of
         the container. A solid background is used for contrast
         with the content view.
    -->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/bottomMenu1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@color/bottom_menu_unchecked"
            android:gravity="center"
            android:text="@string/bottom_menu_1"
            android:textColor="#ffffff"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/bottomMenu2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@color/bottom_menu_unchecked"
            android:gravity="center"
            android:text="@string/bottom_menu_2"
            android:textColor="#ffffff"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/bottomMenu3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@color/bottom_menu_unchecked"
            android:gravity="center"
            android:text="@string/bottom_menu_3"
            android:textColor="#ffffff"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/bottomMenu4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@color/bottom_menu_unchecked"
            android:gravity="center"
            android:text="@string/bottom_menu_4"
            android:textColor="#ffffff"
            android:textSize="20sp" />
    </LinearLayout>

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="0dip"
        android:layout_gravity="start"
        android:layout_weight="1"
        android:background="#111"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp" />

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

1 个答案:

答案 0 :(得分:4)

将View放在ListView上方,并将其包装在垂直LinearLayout中。给你的ListView android:layout_weight =“1”和android:layout_height =“0dip”