Material Design(九)--CoordinatorLayout和App Bar

來源:互聯網
上載者:User

標籤:

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.