2016-09-07 57 views
-1

我有一個片段內的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" 
    /> 

有人可以請幫我出去

+0

什麼是你想在這裏實現使用的LinearLayout?只有一個屏幕,頂部有工具欄,下方有tablayout? – HourGlass

回答

0

嘗試在您的Framelayout上使用app:layout_behavior="@string/appbar_scrolling_view_behavior"

+0

非常感謝...它的工作:) –

+0

okayyy ......... :) –

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> 
相關問題