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手機(jī)管家懸浮小火箭效果
- Android仿360桌面手機(jī)衛(wèi)士懸浮窗效果
- Android使用自定義PageTransformer實現(xiàn)個性的ViewPager動畫切換效果
- Android實現(xiàn)雙向滑動特效的實例代碼
相關(guān)文章
Android實現(xiàn)自動變換大小的ViewPager
ViewPager使用適配器類將數(shù)據(jù)和view的處理分離,ViewPager的適配器叫PagerAdapter,這是一個抽象類,不能實例化,所以它有兩個子類:FragmentPagerAdapter 和 FragmentStatePagerAdapter,這兩個都是處理頁面為Fragment的情況2022-11-11如何自己實現(xiàn)Android View Touch事件分發(fā)流程
這篇文章主要介紹了如何自己實現(xiàn)Android View Touch事件分發(fā)流程,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下2021-03-03Android RadioGroup 設(shè)置某一個選中或者不可選中的方法
下面小編就為大家?guī)硪黄狝ndroid RadioGroup 設(shè)置某一個選中或者不可選中的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-04-04如何正確實現(xiàn)Android啟動屏畫面的方法(避免白屏)
本篇文章主要介紹了如何正確實現(xiàn)Android啟動屏畫面的方法(避免白屏),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-02-02Android.mk文件中添加第三方j(luò)ar文件的方法
這篇文章主要介紹了Android.mk文件中添加第三方j(luò)ar文件及引用第三方j(luò)ar包的方法,需要的朋友可以參考下2018-01-01