Android5.0推出的MaterialDesign庫包含了處理頭部工具欄的多個控件,不但允許自定義頂部導(dǎo)航欄,而且導(dǎo)航欄高度是可以伸縮的。如此一來,一方面導(dǎo)航欄能夠放得下更多控件,另一方面在用戶想看具體內(nèi)容時也能騰出更多的屏幕空間。
成都創(chuàng)新互聯(lián)主營雙陽網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,手機(jī)APP定制開發(fā),雙陽h5小程序開發(fā)搭建,雙陽網(wǎng)站營銷推廣歡迎雙陽等地區(qū)企業(yè)咨詢這么說可能比較抽象,那就先來看看兩張導(dǎo)航欄的效果圖,第一張是導(dǎo)航欄完全展開時的界面,此時頁面頭部的導(dǎo)航欄占據(jù)了較大部分的高度;
第二張是導(dǎo)航欄完全收縮時的界面,此時頭部導(dǎo)航欄只剩矮矮的一個長條。
看起來很眼熟是不是,上面的截圖正是仿支付寶首頁的頭部效果。如果你熟悉AppBarLayout和CollapsingToolbarLayout的話,也許可以很快做出類似以上的簡單界面,具體地說,就是定義一個CoordinatorLayout嵌套AppBarLayout再嵌套CollapsingToolbarLayout再嵌套Toolbar的布局。之所以要嵌套這么多層,是因為要完成以下功能:
1、CoordinatorLayout嵌套AppBarLayout,這是為了讓頭部導(dǎo)航欄能夠跟隨內(nèi)容視圖下拉而展開,跟隨內(nèi)容視圖上拉而收縮。這個內(nèi)容視圖可以是RecyclerView,也可以是NestedScrollView;
2、AppBarLayout嵌套CollapsingToolbarLayout,這是為了定義導(dǎo)航欄下面需要展開和收縮的部分視圖;
3、CollapsingToolbarLayout嵌套Toolbar,這是為了定義導(dǎo)航欄上方無論何時都要顯示的長條區(qū)域,其中Toolbar還要定義兩個不同的樣式布局,用于分別顯示展開與收縮狀態(tài)時的工具欄界面。
下面是基于以上思路實現(xiàn)的布局文件代碼:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" > <android.support.design.widget.AppBarLayout android:id="@+id/abl_bar" android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" > <android.support.design.widget.CollapsingToolbarLayout android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" app:layout_scrollFlags="scroll|exitUntilCollapsed|snap" app:contentScrim="@color/blue_dark" > <include android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/toolbar_height" app:layout_collapseMode="parallax" app:layout_collapseParallaxMultiplier="0.7" layout="@layout/life_pay" /> <android.support.v7.widget.Toolbar android:layout_width="match_parent" android:layout_height="@dimen/toolbar_height" app:layout_collapseMode="pin" app:contentInsetLeft="0dp" app:contentInsetStart="0dp" > <include android:id="@+id/tl_expand" android:layout_width="match_parent" android:layout_height="match_parent" layout="@layout/toolbar_expand" /> <include android:id="@+id/tl_collapse" android:layout_width="match_parent" android:layout_height="match_parent" layout="@layout/toolbar_collapse" android:visibility="gone" /> </android.support.v7.widget.Toolbar> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.v7.widget.RecyclerView android:id="@+id/rv_content" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="10dp" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </android.support.design.widget.CoordinatorLayout>
網(wǎng)頁標(biāo)題:Android仿支付寶的頭部伸縮動畫效果-創(chuàng)新互聯(lián)
文章位置:http://muchs.cn/article18/cdojdp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、網(wǎng)站內(nèi)鏈、自適應(yīng)網(wǎng)站、品牌網(wǎng)站制作、ChatGPT、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容