我想創建一些使用CoordinatorLayout和CollapsingToolbarLayout的組合佈局。CollapsingToolbarLayout並滾動時隱藏工具欄
在第一狀態下,當我們最頂級的網頁上,卻沒有滾動,我希望工具欄花費如下所示(是的,我做到了):
在第二個狀態,開始向下滾動時,圖像和工具欄將會消失,如下圖所示(僅標籤會顯示):
而且在最後的狀態,一旦我在一些點列表(但不是頂部)我想開始向上滾動,一旦我開始向上滾動,我想要工具欄(而不是擴展的圖像)開始播放,如下所示(如果沒有到達列表的頂部,圖像將無法顯示,只有工具欄):
我能才達到的第一狀態,但其他2狀態是有問題的, 一旦工具欄裏面CollapsingToolbarLayout實施的flexability的我可以在CollapsingToolbarLayout組件之外使用它做不清楚。 我不能讓工具欄隱藏,如果我這樣做,那麼只有當我到達頂部時纔會顯示它。
無論如何,我的當前XML(如下所示)處於第一張圖片實現的狀態,但是一旦我開始向下滾動,工具欄將停留在頂部而不會隱藏。注意:我必須告訴工具欄保持「pin」狀態,因爲如果沒有,那麼工具欄中的信息就會消失,只會顯示一個空的工具欄(這是另一篇文章,但仍然很有趣,知道爲什麼會發生這種情況?) 。
這裏是我當前xml:
<android.support.design.widget.CoordinatorLayout
android:id="@+id/benefit_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_material_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
<include
android:id="@+id/toolbar_search_container"
layout="@layout/search_box"
android:layout_height="192dp"
android:layout_width="match_parent"
app:layout_collapseMode="parallax"
/>
<include
android:id="@+id/toolbar_benefit"
layout="@layout/toolbar_main"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:contentScrim="?attr/colorPrimary"
/>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.TabLayout
android:id="@+id/benefit_tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primaryColor"
app:tabIndicatorColor="@color/accentColor"
app:tabSelectedTextColor="@android:color/white"
app:tabTextColor="@android:color/black"
app:tabIndicatorHeight="4dp" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/benefit_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<include
layout="@layout/floating_btn_benefits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
/>
</android.support.design.widget.CoordinatorLayou
非常感謝!我發現這個答案很難,因爲很難向谷歌解釋問題。我已經嘗試了幾乎所有的可能性,但錯過了使用ALL 3屬性。應該讓更多的人知道答案! –
我照你所說的做了,但是當我向上滾動時,我的CollapsingToolbarLayout將不會出現,直到我滾動到頂部。你能提出什麼建議嗎? – Sermilion
嘿冬天!你可以在這裏發佈你的完整的XML嗎?沒有 - 標籤?謝謝!!! –
romaneso