Android實(shí)現(xiàn)滑動(dòng)到頂部懸停的效果
先來看下要實(shí)現(xiàn)效果圖:
查閱資料后,發(fā)現(xiàn)網(wǎng)上大部分都是用這種方法實(shí)現(xiàn)的:
多寫一個(gè)和需要懸浮的部分一模一樣的layout
,先把浮動(dòng)區(qū)域的可見性設(shè)置為gone
。當(dāng)浮動(dòng)區(qū)域滑動(dòng)到頂部的時(shí)候,就把浮動(dòng)區(qū)域B的可見性設(shè)置為VISIBLE
。這樣看起來就像懸浮在頂部不動(dòng)了。
這里介紹的是另外一種方式:
使用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>
實(shí)現(xiàn)步驟:
1、將需要懸浮的layout
放到CollapsingToolbarLayout
之外,AppBarLayout
之內(nèi)
2、將CollapsingToolbarLayout
的app:layout_scrollFlags
設(shè)置為scroll
3、給滾動(dòng)的NestedScroolView
設(shè)置
app:layout_behavior="@String/appbar_scrolling_view_behavior"
就大功告成了(記得根布局要是CoordinatorLayout)
最終效果:
總結(jié)
以上就是關(guān)于Android滑動(dòng)到頂部懸停效果的全部內(nèi)容,大家都學(xué)會(huì)了嗎?希望這篇文章對(duì)大家的學(xué)習(xí)或者工作帶來一定的幫助,如果有疑問大家可以留言交流。
- Android實(shí)現(xiàn)上下菜單雙向滑動(dòng)效果
- Android仿人人客戶端滑動(dòng)菜單的側(cè)滑菜單效果
- Android利用滑動(dòng)菜單框架實(shí)現(xiàn)滑動(dòng)菜單效果
- Android程序開發(fā)之使用Design包實(shí)現(xiàn)QQ動(dòng)畫側(cè)滑效果和滑動(dòng)菜單導(dǎo)航
- 解析Android中實(shí)現(xiàn)滑動(dòng)翻頁之ViewFlipper的使用詳解
- android開發(fā)教程之實(shí)現(xiàn)滑動(dòng)關(guān)閉fragment示例
- Android利用ViewPager實(shí)現(xiàn)滑動(dòng)廣告板實(shí)例源碼
- Android App中使用ViewPager+Fragment實(shí)現(xiàn)滑動(dòng)切換效果
- Android中ScrollView實(shí)現(xiàn)滑動(dòng)距離監(jiān)聽器的方法
- Android實(shí)現(xiàn)QQ手機(jī)管家懸浮小火箭效果
- Android仿360桌面手機(jī)衛(wèi)士懸浮窗效果
- Android使用自定義PageTransformer實(shí)現(xiàn)個(gè)性的ViewPager動(dòng)畫切換效果
- Android實(shí)現(xiàn)雙向滑動(dòng)特效的實(shí)例代碼
相關(guān)文章
Android實(shí)現(xiàn)自動(dòng)變換大小的ViewPager
ViewPager使用適配器類將數(shù)據(jù)和view的處理分離,ViewPager的適配器叫PagerAdapter,這是一個(gè)抽象類,不能實(shí)例化,所以它有兩個(gè)子類:FragmentPagerAdapter 和 FragmentStatePagerAdapter,這兩個(gè)都是處理頁面為Fragment的情況2022-11-11如何自己實(shí)現(xiàn)Android View Touch事件分發(fā)流程
這篇文章主要介紹了如何自己實(shí)現(xiàn)Android View Touch事件分發(fā)流程,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下2021-03-03Android結(jié)合xml實(shí)現(xiàn)幀動(dòng)畫
將一組動(dòng)作相近的圖片組合在一起,然后按照一定的時(shí)間來播放,就會(huì)形成一個(gè)動(dòng)畫,我們可以稱之為幀動(dòng)畫。在 Android 中可通過結(jié)合 xml 的方式來輕松實(shí)現(xiàn)。2021-05-05android編程實(shí)現(xiàn)圖片庫的封裝方法
這篇文章主要介紹了android編程實(shí)現(xiàn)圖片庫的封裝方法,涉及Android針對(duì)圖片的下載、保存、獲取及操作緩存圖片等相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11Android RadioGroup 設(shè)置某一個(gè)選中或者不可選中的方法
下面小編就為大家?guī)硪黄狝ndroid RadioGroup 設(shè)置某一個(gè)選中或者不可選中的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-04-04Android實(shí)現(xiàn)登錄界面記住密碼的存儲(chǔ)
這篇文章主要為大家詳細(xì)介紹了Android SharedPreferrences實(shí)現(xiàn)登錄界面記住密碼的存儲(chǔ),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04如何正確實(shí)現(xiàn)Android啟動(dòng)屏畫面的方法(避免白屏)
本篇文章主要介紹了如何正確實(shí)現(xiàn)Android啟動(dòng)屏畫面的方法(避免白屏),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-02-02Android.mk文件中添加第三方j(luò)ar文件的方法
這篇文章主要介紹了Android.mk文件中添加第三方j(luò)ar文件及引用第三方j(luò)ar包的方法,需要的朋友可以參考下2018-01-01