Android BottomSheet實(shí)現(xiàn)可拉伸控件
一、簡(jiǎn)介
Bottom Sheet是Design Support Library23.2 版本引入的一個(gè)類似于對(duì)話框的控件。 Bottom Sheet中的內(nèi)容默認(rèn)是隱藏起來的,只顯示很小一部分,可以通過在代碼中設(shè)置其狀態(tài)或者手勢(shì)操作將其完全展開,或者完全隱藏,或者部分隱藏。
二、使用
1、添加依賴:
implementation 'com.android.support:design:28.0.0'
2、布局
<?xml version="1.0" encoding="utf-8"?> <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:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <com.amap.api.maps.MapView android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" /> <RelativeLayout android:id="@+id/bottom_sheet" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/height52px" app:behavior_hideable="false" app:behavior_peekHeight="@dimen/height84px" app:layout_behavior="android.support.design.widget.BottomSheetBehavior" tools:ignore="MissingPrefix" android:background="#ffffffff" > <include layout="@layout/bottom_sheet" /> </RelativeLayout> </android.support.design.widget.CoordinatorLayout> <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="@dimen/height216px" > <TextView android:layout_width="match_parent" android:layout_height="100dp" android:gravity="center" android:text="bottom_sheet_peek" /> </RelativeLayout>
3、代碼實(shí)現(xiàn)
//底部抽屜欄展示地址 mBehavior = BottomSheetBehavior.from(mRelativeLayout); mBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { @Override public void onStateChanged(@NonNull View bottomSheet, @BottomSheetBehavior.State int newState) { String state = "null"; switch (newState) { case 1: state = "STATE_DRAGGING";//過渡狀態(tài)此時(shí)用戶正在向上或者向下拖動(dòng)bottom sheet break; case 2: state = "STATE_SETTLING"; // 視圖從脫離手指自由滑動(dòng)到最終停下的這一小段時(shí)間 break; case 3: state = "STATE_EXPANDED"; //處于完全展開的狀態(tài) break; case 4: state = "STATE_COLLAPSED"; //默認(rèn)的折疊狀態(tài) break; case 5: state = "STATE_HIDDEN"; //下滑動(dòng)完全隱藏 bottom sheet break; } } @Override public void onSlide(@NonNull View bottomSheet, float slideOffset) { Log.i("BottomSheetDemo", "slideOffset:" + slideOffset); } });
4、幾個(gè)屬性含義:
// behavior_hideable:定義是否能通過下滑手勢(shì)收起B(yǎng)ottom Sheet。 app:behavior_hideable="true" // behavior_peekHeight:定義可見部分的高度。 app:behavior_peekHeight="80dp" app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
5、BottomSheet的五種狀態(tài):
STATE_DRAGGING:手指在BottomSheet上下拖動(dòng)從而使得布局跟著上下移動(dòng)
STATE_SETTLING:當(dāng)手指抬起之后,會(huì)根據(jù)當(dāng)前的偏移量,決定是要將BottomSheet收起還是展開
這兩種屬于中間態(tài),類似于ViewPager的SCROLL_STATE_DRAGGING和SCROLL_STATE_SETTLING
--------------------------------------
STATE_EXPANDED:展開
STATE_COLLAPSED:收起
STATE_HIDDEN:隱藏
三、封裝的框架推薦
Flipboard/bottomsheet
soarcn/BottomSheet
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。
上一篇:android使用surfaceview+MediaPlayer 視頻
欄 目:Android
本文標(biāo)題:Android BottomSheet實(shí)現(xiàn)可拉伸控件
本文地址:http://mengdiqiu.com.cn/a1/Android/9077.html
您可能感興趣的文章
- 01-10Android自定義View之繪制圓形頭像功能
- 01-10Android實(shí)現(xiàn)雙擊返回鍵退出應(yīng)用實(shí)現(xiàn)方法詳解
- 01-10android實(shí)現(xiàn)記住用戶名和密碼以及自動(dòng)登錄
- 01-10android實(shí)現(xiàn)簡(jiǎn)單計(jì)算器功能
- 01-10Android 友盟第三方登錄與分享的實(shí)現(xiàn)代碼
- 01-10C++自定義API函數(shù)實(shí)現(xiàn)大數(shù)相乘算法
- 01-10如何給Flutter界面切換實(shí)現(xiàn)點(diǎn)特效
- 01-10android實(shí)現(xiàn)指紋識(shí)別功能
- 01-10Emoji表情在Android JNI中的兼容性問題詳解
- 01-10Android實(shí)現(xiàn)圓形漸變加載進(jìn)度條


閱讀排行
- 1C語(yǔ)言 while語(yǔ)句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹的示例代碼(圣誕
- 3利用C語(yǔ)言實(shí)現(xiàn)“百馬百擔(dān)”問題方法
- 4C語(yǔ)言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語(yǔ)言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語(yǔ)言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語(yǔ)言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 01-10Android自定義View之繪制圓形頭像功能
- 01-10Android實(shí)現(xiàn)雙擊返回鍵退出應(yīng)用實(shí)現(xiàn)方
- 01-10android實(shí)現(xiàn)簡(jiǎn)單計(jì)算器功能
- 01-10android實(shí)現(xiàn)記住用戶名和密碼以及自動(dòng)
- 01-10C++自定義API函數(shù)實(shí)現(xiàn)大數(shù)相乘算法
- 01-10Android 友盟第三方登錄與分享的實(shí)現(xiàn)代
- 01-10android實(shí)現(xiàn)指紋識(shí)別功能
- 01-10如何給Flutter界面切換實(shí)現(xiàn)點(diǎn)特效
- 01-10Android實(shí)現(xiàn)圓形漸變加載進(jìn)度條
- 01-10Emoji表情在Android JNI中的兼容性問題詳
隨機(jī)閱讀
- 04-02jquery與jsp,用jquery
- 01-10使用C語(yǔ)言求解撲克牌的順子及n個(gè)骰子
- 01-10C#中split用法實(shí)例總結(jié)
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 01-10delphi制作wav文件的方法
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 01-11ajax實(shí)現(xiàn)頁(yè)面的局部加載