如何在工具栏之后放置选项卡布局?

How to place tab layout after toolbar?

我在片段中有一个 tablayout 和一个 viewpager。我的 tablayout 中有两个选项卡。和我的 app_bar_main.xml 中的工具栏。但是当我 运行 我的应用程序 tablayout 隐藏了工具栏。如何将它放在工具栏之后? 这是我的代码 这是我的 app_bar_main.xml 文件

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#CC0000"
        android:titleTextColor="@color/white"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<FrameLayout
    android:id="@+id/fragment_containerlayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFFFFF"></FrameLayout>

这是我的片段设计,我在其中放置了一个选项卡布局和一个视图寻呼机

<FrameLayout 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="com.example.nayab.demotask.ContactsFragment"
xmlns:app="http://schemas.android.com/apk/res-auto">


<android.support.design.widget.TabLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/contactstablayot"
    android:layout_gravity="left|top"
    android:background="#000000"
    app:tabTextColor="@android:color/white"
    />

<android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/fragviewpager"
    android:layout_gravity="left|center_vertical"
    android:layout_marginTop="30dp"
    android:background="#e6f1f5"
    />

有人能帮帮我吗

尝试在您的框架布局上使用 app:layout_behavior="@string/appbar_scrolling_view_behavior"

您可以使用垂直方向的线性布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

       <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="#CC0000"
            android:titleTextColor="@color/white"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:id="@+id/fragment_containerlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"></FrameLayout>

</LinearLayout>