Material Design(十)--CoordinatorLayout和App Bar

來源:互聯網
上載者:User

標籤:

把Toobar直接添加到AppBarLayout裡面給予了你enterAlwayCollapsed和exitUntilCollapsed這些滾動標籤的存取權限,而不是對不同元素如何對collapsing作出響應的詳細控制項能力。要想擷取後者的效果,你可以使用CollapsingToolbarLayout:

 1 <android.support.design.widget.AppBarLayout 2         android:layout_height=‘192dp‘ 3         android:layout_width=‘match_parent‘> 4     <android.support.design.widget.CollapsingToolbarLayout 5             android:layout_width=‘match_parent‘ 6             android:layout_height=‘match_parent‘ 7             app:layout_scrollFlags=‘scroll|exitUntilCollapsed‘> 8         <android.support.v7.widget.Toolbar 9                 android:layout_height=‘?attr/actionBarSize‘10                 android:layout_width=‘match_parent‘11                 app:layout_collapseMode=‘pin‘/>12         </android.support.design.widget.CollapsingToolbarLayout>13 </android.support.design.widget.AppBarLayout>

以上設定使用了CollapsingToolbarLayout的app:layout_collapseMode=”pin”屬性以確保Toolbar本身在視圖collapse的時候依然能夠被訂在螢幕頂部。而可能更多的情況是,在你一起使用CollapsingToolbarLayout和Toolbar的時候,當布局完全可見的時候,標題將自動顯示得更大,然後在toolbar collapse的時候過渡到它的預設尺寸。請注意在這些情況下,你應該調用CollapsingToolbarLayot的setTittle(),而非Toolbar本身的setTitle()。

查看Collapsing Toolbar效果請點擊(打不開時候注意FQ)

除了可以訂住一個視圖之外,你能夠使用app:layout_collapseMode=”parallax”(可選情況下,使用app:layout_collapseParallaxMultiplier=”0.7”來設定滾動視差乘法因子)來實現滾動視差效果(例如CollapsingToolbarLayout內部的兄弟ImageView)。這個使用樣本將app:layout_collapseParallaxMultiplier和CollapsingToolbarLayout的app:contentScrim=”?attr/colorPrimary”配成對使用,結果是在視圖collapse時,添加了全出血紗布效果。

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.