如何在工具栏后放置标签布局?

时间:2016-09-07 07:43:44

标签: android xml android-viewpager toolbar android-tablayout

我在片段中有一个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"
    />

有人可以帮帮我吗

2 个答案:

答案 0 :(得分:0)

尝试在Framelayout上使用app:layout_behavior="@string/appbar_scrolling_view_behavior"

答案 1 :(得分:0)

你可以使用带有垂直方向的线性布局

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