Android實現(xiàn)滑動到頂部懸停的效果
先來看下要實現(xiàn)效果圖:

查閱資料后,發(fā)現(xiàn)網(wǎng)上大部分都是用這種方法實現(xiàn)的:
多寫一個和需要懸浮的部分一模一樣的layout,先把浮動區(qū)域的可見性設(shè)置為gone。當(dāng)浮動區(qū)域滑動到頂部的時候,就把浮動區(qū)域B的可見性設(shè)置為VISIBLE。這樣看起來就像懸浮在頂部不動了。
這里介紹的是另外一種方式:
使用design包中的控件
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context="com.peipei.app.MainActivity"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="250dp"> <android.support.design.widget.CollapsingToolbarLayout app:layout_scrollFlags="scroll" app:contentScrim="#000000" android:layout_width="match_parent" android:layout_height="220dp"> <TextView android:text="banner區(qū)域" android:gravity="center" android:textColor="#ffffff" android:background="#987545" android:layout_width="match_parent" android:layout_height="220dp"/> </android.support.design.widget.CollapsingToolbarLayout> <TextView android:gravity="center" android:layout_width="match_parent" android:layout_height="30dp" android:text="懸浮的部分"/> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="@dimen/text_margin" android:text="@string/large_text"/> </android.support.v4.widget.NestedScrollView> </android.support.design.widget.CoordinatorLayout>
實現(xiàn)步驟:
1、將需要懸浮的layout放到CollapsingToolbarLayout之外,AppBarLayout之內(nèi)
2、將CollapsingToolbarLayout的app:layout_scrollFlags設(shè)置為scroll
3、給滾動的NestedScroolView設(shè)置
app:layout_behavior="@String/appbar_scrolling_view_behavior"
就大功告成了(記得根布局要是CoordinatorLayout)
最終效果:

總結(jié)
以上就是關(guān)于Android滑動到頂部懸停效果的全部內(nèi)容,大家都學(xué)會了嗎?希望這篇文章對大家的學(xué)習(xí)或者工作帶來一定的幫助,如果有疑問大家可以留言交流。
- Android實現(xiàn)上下菜單雙向滑動效果
- Android仿人人客戶端滑動菜單的側(cè)滑菜單效果
- Android利用滑動菜單框架實現(xiàn)滑動菜單效果
- Android程序開發(fā)之使用Design包實現(xiàn)QQ動畫側(cè)滑效果和滑動菜單導(dǎo)航
- 解析Android中實現(xiàn)滑動翻頁之ViewFlipper的使用詳解
- android開發(fā)教程之實現(xiàn)滑動關(guān)閉fragment示例
- Android利用ViewPager實現(xiàn)滑動廣告板實例源碼
- Android App中使用ViewPager+Fragment實現(xiàn)滑動切換效果
- Android中ScrollView實現(xiàn)滑動距離監(jiān)聽器的方法
- Android實現(xiàn)QQ手機管家懸浮小火箭效果
- Android仿360桌面手機衛(wèi)士懸浮窗效果
- Android使用自定義PageTransformer實現(xiàn)個性的ViewPager動畫切換效果
- Android實現(xiàn)雙向滑動特效的實例代碼
相關(guān)文章
Android組件必學(xué)之TabHost使用方法詳解
這篇文章主要為大家詳細(xì)介紹了Android組件中的TabHost組件使用方法,如何利用TabHost定義Tab標(biāo)簽樣式,感興趣的小伙伴們可以參考一下2016-05-05
android通過Location API顯示地址信息的實現(xiàn)方法
這篇文章主要介紹了android通過Location API顯示地址信息的方法,涉及Android操作Geocoder類獲取地址信息的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07
android開發(fā)教程之間隔執(zhí)行程序(android計時器)
android開發(fā)中有些情況需要隔一段時間去執(zhí)行某個操作一次或者是每隔一段時間久執(zhí)行某個操作,下面是實現(xiàn)方法2014-02-02
Android實現(xiàn)單頁面浮層可拖動view的一種方法
本篇文章主要介紹了Android實現(xiàn)單頁面浮層可拖動view的一種方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-10-10
Android中 視頻屏幕左半部分上下滑動改變亮度右半部分上下滑動改變聲音
這篇文章主要介紹了Android中 視頻屏幕左半部分上下滑動改變亮度右半部分上下滑動改變聲音的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-09-09
Android Back鍵點擊兩次退出應(yīng)用詳解及實現(xiàn)方法總結(jié)
這篇文章主要介紹了Android Back鍵點擊兩次退出應(yīng)用詳解及實現(xiàn)方法總結(jié)的相關(guān)資料,需要的朋友可以參考下2016-10-10
android實現(xiàn)漢字轉(zhuǎn)拼音功能 帶多音字識別
這篇文章主要介紹了android實現(xiàn)漢字轉(zhuǎn)拼音功能,帶多音字識別,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-02-02

