2016-01-24 36 views
2

有沒有辦法讓2個CollapsingToolbarLayouts(一個在另一個之下)可以一個接一個地展開/摺疊?有2 CollapsingToolbarLayout可以一個接一個地展開/摺疊

讓我們這個圖像作爲一個例子:

enter image description here

的部分1和2是兩個CollapsingToolbarLayouts(和每一個包含一個工具欄我想),並且部分3是一個列表(一個RecyclerView )可以滾動。

用戶可以在部分3上滾動,並且它會摺疊部分1.一旦部分1完全摺疊,它將摺疊部分2.一旦2個佈局摺疊,用戶可以繼續滾動列表。

如果用戶在另一個方向滾動,他將首先到達列表的頂部,然後如果他繼續滾動,則會展開第2部分,然後在第2部分展開後展開第1部分完全展開。

回答

0

我希望這是你在找什麼:app:layout_collapseMode="parallax"應該做的:

例的伎倆:

<?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:id="@+id/drawer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#EEEEEE" 
    android:fitsSystemWindows="true" 
    tools:context=".MainActivity"> 

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 


     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 


      <Button 
       android:id="@+id/button" 
       android:layout_width="wrap_content" 
       android:layout_height="250dp" 
       android:text="New Button" /> 

      <Button 
       android:id="@+id/button2" 
       android:layout_width="wrap_content" 
       android:layout_height="250dp" 
       android:text="New Button" /> 

      <Button 
       android:id="@+id/button3" 
       android:layout_width="wrap_content" 
       android:layout_height="250dp" 
       android:text="New Button" /> 

      <Button 
       android:id="@+id/button4" 
       android:layout_width="wrap_content" 
       android:layout_height="250dp" 
       android:text="New Button" /> 
     </LinearLayout> 


    </android.support.v4.widget.NestedScrollView> 

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

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/toolbarCollapse" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

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

       <ImageView 
        android:layout_width="match_parent" 
        android:layout_height="100dp" 
        android:minHeight="190dp" 
        android:src="@mipmap/ic_launcher" 
        app:layout_collapseMode="parallax" /> 

       <ImageView 
        android:layout_width="match_parent" 
        android:layout_height="100dp" 
        android:layout_marginTop="102dp" 
        android:minHeight="190dp" 
        android:scaleType="fitXY" 
        android:src="@drawable/social" 
        app:layout_collapseMode="parallax" /> 


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

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

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

此外,你可能想看一看:app:layout_scrollFlags

標記

http://developer.android.com/reference/android/support/design/widget/AppBarLayout.LayoutParams.html

此外,有兩個工具欄是不是一個好主意,我想你要找的TabLayout,這樣的例子:

https://github.com/TheLittleNaruto/SupportDesignExample

+0

我不知道TabLayout正是我需要的;我需要意識到這樣的事情:https://www.dropbox.com/s/yi9nk7b4jg4v813/2a_08.mp4?dl=0(注意2個酒吧是如何一個接一個地倒塌的) – IKIKN2

+0

我的意思是,像上面的例子,請參閱gif:https://camo.githubusercontent.com/4e116716b3ddb76b845c5bcb588b6d69b29d4310/687474703a2f2f692e737461636b2e696d6775722e636f6d2f714b6561462e676966你應該可以添加'Toolbar'(或者本例中的'CollapsingToolbarLayout',它是一個'TabLayout'),就像這個例子: https://github.com/TheLittleNaruto/SupportDesignExample/blob/master/app/src/main/res/layout/app_container_view.xml這是你的解決方案。 – Mohsen

+0

或者你應該在視圖中加入這個:'app:layout_collapseMode =「pin」'如果你在'CollapsingToolbarLayout'中使用這個' – Mohsen