2016-02-22 32 views

回答

1

請發佈您當前使用的佈局文件。

應該有辦法做到這一點。您將在CollapsingToolbarLayout中有兩個工具欄。您在摺疊工具欄上使用app:toolbarId指定的一個工具欄作爲摺疊工具欄。在此工具欄上,您可以設置主頁/後退圖標和選項菜單。不同的工具欄應該是摺疊佈局的第一個子元素,並且具有app:layout_collapseMode="pin"。在此工具欄上,您可以設置標題和可選的字幕。

這是我一直在玩的佈局,我不得不拿出fitsSystemWindows使它看起來更好。試試看:

<?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" 
    tools:context="com.example.pinnedtoolbar.ScrollingActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/app_bar" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/app_bar_height" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/toolbar_layout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:toolbarId="@+id/toolbar" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="?attr/actionBarSize" 
       android:src="@drawable/abby" 
       android:scaleType="centerCrop" 
       app:layout_collapseMode="parallax"/> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/titleToolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="?attr/colorPrimary" 
       app:layout_collapseMode="pin" /> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:layout_collapseMode="pin" 
       app:popupTheme="@style/AppTheme.PopupOverlay" /> 

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

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

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@android:drawable/ic_dialog_email" 
     app:layout_anchor="@id/app_bar" 
     app:layout_anchorGravity="bottom|end" /> 

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

下面是一些與它一起去的代碼:

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_scrolling); 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

     // erase the expanded title  
     getSupportActionBar().setTitle(null); 

     // set the title on the other pinned toolbar 
     Toolbar titleToolbar = (Toolbar) findViewById(R.id.titleToolbar); 
     titleToolbar.setTitle("This is the real title"); 

    } 
+0

謝謝@kris拉森 –

相關問題