如何让我的导航抽屉始终位于一切之上? ANDROID

时间:2016-10-20 09:57:01

标签: android xml

有没有办法让我的导航栏保持在我的活动中的所有内容之上或叠加或重叠?

我在main_activity.xml中有这段代码

<android.support.v4.widget.DrawerLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:id="@+id/drawer_layout"
    android:layout_weight="1"
    >
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/frame_container"
        >
    </FrameLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        />

    <!-- Listview to display slider menu -->
    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:listSelector="@drawable/list_selector"
        android:background="#FFF"/>

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

<android.support.design.widget.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFF"
    android:minHeight="?attr/actionBarSize"
    app:tabIndicatorHeight="5dp"
    app:tabIndicatorColor="@color/colorPrimary"
    />

</LinearLayout>

我现在遇到的问题是,即使我显示了导航抽屉,我的tablayout也会一直显示。有谁知道如何帮助我?

您的回答将不胜感激。

this is the screen shot of my current situation

即使我有导航抽屉显示,你能看到tablayout仍然存在吗?

2 个答案:

答案 0 :(得分:1)

要让NavigationDrawer置于其他所有内容之上,您的DrawerLayout必须是所有观看次数的父级布局。

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    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">


        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFF"
            android:minHeight="?attr/actionBarSize"
            app:tabIndicatorColor="@color/colorPrimary"
            app:tabIndicatorHeight="5dp" />


        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
    </LinearLayout>

    <!-- Listview to display slider menu -->
    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#FFF"
        android:choiceMode="singleChoice" />

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

答案 1 :(得分:0)

尝试放置 TabLayout 内部抽屉布局

<android.support.v4.widget.DrawerLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:id="@+id/drawer_layout"
    android:layout_weight="1"
    >
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/frame_container"
        >
    </FrameLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        />

    <!-- Listview to display slider menu -->
    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:listSelector="@drawable/list_selector"
        android:background="#FFF"/>


<android.support.design.widget.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFF"
    android:minHeight="?attr/actionBarSize"
    app:tabIndicatorHeight="5dp"
    app:tabIndicatorColor="@color/colorPrimary"
    />

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

</LinearLayout>