標籤:
CoordinatorLayout的其它主要使用執行個體包括app bar(即先前的action bar)和滾動技術。你也許已經在布局中使用Toolbar了,Toolbar允許你輕易地自訂外觀和應用中表徵圖部分與布局的整合。Design包在這一點走得更遠:使用AppBarLayout允許Toolbar和其它的視圖(如TabLayout提供了tab)對標記了ScrollingViewBehavior的兄弟視圖中的滾動事件產生反饋。由此,你可以像這樣建立布局:
1 <android.support.design.widget.CoordinatorLayout 2 xmlns:android=‘http://schemas.android.com/apk/res/android‘ 3 xmlns:app=‘http://schemas.android.com/apk/res-auto‘ 4 android:layout_width=‘match_parent‘ 5 android:layout_height=‘match_parent‘> 6 7 <! -- Your Scrollable View --> 8 <android.support.v7.widget.RecyclerView 9 android:layout_width=‘match_parent‘10 android:layout_height=‘match_parent‘11 app:layout_behavior=‘@string/appbar_scrolling_view_behavior‘ />12 13 <android.support.design.widget.AppBarLayout14 android:layout_width=‘match_parent‘15 android:layout_height=‘wrap_content‘>16 <android.support.v7.widget.Toolbar17 ...18 app:layout_scrollFlags=‘scroll|enterAlways‘>19 20 <android.support.design.widget.TabLayout21 ...22 app:layout_scrollFlags=‘scroll|enterAlways‘>23 </android.support.design.widget.AppBarLayout>24 </android.support.design.widget.CoordinatorLayout>
現在,在使用者使用RecyclerView的時候,AppBarLayout能夠對通過使用子視圖的滾動標籤來控制項他們如何滾進和滾出螢幕的事件進行響應。這些標籤包括:
scroll:這個標籤應該是想要滾出螢幕的所有視圖的集合—對於那些並不使用這個標籤的視圖,他們而被訂在螢幕的頂部。 enterAlways:這個標籤確保任何向下的滑動都會使得這個視圖可見,啟用了“快速返回”模式。 exitUntilCollapsed:這個標籤使得視圖不會滾動出來,除非在退出之前該視圖變得“collapsed”(它的minHeight)。
注意一點:所有使用scroll標籤的視圖必須在不使用該標籤的視圖之前聲明。這將確保所有的視圖從頂部退出,而把固定的元素落下。
Material Design(九)--CoordinatorLayout和App Bar