2017-01-05 28 views
0

針的RelativeLayout我使用CollapsingToolbarLayout我的活動。有沒有辦法將包含工具欄的RelativeLayout固定在工具欄中,而不是固定工具欄?我試圖做到以下幾點,但是當佈局崩潰時,RelativeLayout不會位於頂部。如何CollapsingToolbarLayout

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appBarLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:elevation="0dp" 
     android:theme="@style/AppTheme.AppBarOverlay" 
     app:elevation="0dp" 
     android:fitsSystemWindows="true"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:contentScrim="@color/pale_red" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      android:fitsSystemWindows="true"> 

      <FrameLayout 
       android:layout_width="match_parent" 
       android:layout_height="230dp" 
       android:fitsSystemWindows="true" 
       app:layout_collapseMode="parallax"> 

       <android.support.v4.view.ViewPager 
        android:id="@+id/carViewPager" 
        android:layout_width="match_parent" 
        android:layout_height="230dp"/> 

       <LinearLayout 
        android:id="@+id/image_count" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal" 
        android:gravity="center" 
        android:layout_gravity="bottom|center" 
        android:background="@android:color/transparent" /> 

      </FrameLayout> 

      <RelativeLayout 
       android:id="@+id/toolbarLayout" 
       android:layout_width="match_parent" 
       android:layout_height="@dimen/toolbar_height" 
       app:layout_collapseMode="pin" 
       app:popupTheme="@style/AppTheme.PopupOverlay"> 

       <android.support.v7.widget.Toolbar 
        android:id="@+id/toolbar" 
        android:layout_width="match_parent" 
        android:layout_height="@dimen/toolbar_height" 
        app:popupTheme="@style/AppTheme.PopupOverlay"> 

       </android.support.v7.widget.Toolbar> 

       <TextView 
        android:id="@+id/activityTitle" 
        android:layout_width="match_parent" 
        android:layout_height="48dp" 
        android:layout_gravity="center" 
        android:gravity="center" 
        android:textSize="16sp" 
        android:text="@string/shop_info" 
        android:textColor="@color/white" /> 

      </RelativeLayout> 

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

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

    <include layout="@layout/content_shop" /> 

</android.support.design.widget.CoordinatorLayout> 
+0

如何去除** ** RelativeLayout的放** **的TextView裏面的** **的工具欄好 –

+0

剛剛試過,但TextView中沒有默認情況下消失。我希望TextView只在佈局摺疊時出現。 – stackyyflow

回答

1

它的名字一樣摺疊,寄託都只是工具欄將要倒塌的時候滾動起來,以針它的唯一方法是使用「」上工具欄,只有工具欄與 「」 的作品。 因此,請嘗試將您的RelativeLayout以外的CollapsingToolBarLayout,但在AppBarLayout,也許這就是你所需要的。

我解決它通過這樣一個問題:

How to use a TabLayout with Toolbar inside CollapsingToolbarLayout?

只是把你的佈局在這個問題中提到的TabLayout

希望它有幫助。

相關問題