介绍
这期内容当中小编将会给大家带来有关怎么在Android中使用BottomSheet实现一根根可拉伸控件,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
1,添加依赖:
implementation & # 39; com.android.support:设计:28.0.0& # 39;
2,布局
& lt; ? xml version=?.0“,编码=皍tf-8" ?比; & lt; android.support.design.widget.CoordinatorLayout  xmlns: android=癶ttp://schemas.android.com/apk/res/android" xmlns:才能应用=癶ttp://schemas.android.com/apk/res-auto" xmlns:才能工具=癶ttp://schemas.android.com/tools" android:才能取向=皏ertical" android:才能layout_width=癿atch_parent" android:才能layout_height=癿atch_parent"比; , & lt; com.amap.api.maps.MapView才能 ,,,android: id=癅 + id/map" ,,,android: layout_width=癿atch_parent" ,,,android: layout_height=癿atch_parent" ,,,/比; & lt;才能使用 ,,,android: id=癅 + id/bottom_sheet" ,,,android: layout_width=癿atch_parent" ,,,android: layout_height=皐rap_content" ,,,android: layout_marginBottom=癅dimen/height52px" ,,,的应用:behavior_hideable=癴alse" ,,,的应用:behavior_peekHeight=癅dimen/height84px" ,,,的应用:layout_behavior=癮ndroid.support.design.widget.BottomSheetBehavior" ,,,工具:忽视=癕issingPrefix" ,,,android:背景=? ffffffff" ,,,的在 , ,,,& lt; include 布局=癅layout/bottom_sheet",/比; & lt;才能/RelativeLayout> , & lt;/android.support.design.widget.CoordinatorLayout> & lt; ? xml version=?.0“,编码=皍tf-8" ?比; & lt; RelativeLayout  xmlns: android=癶ttp://schemas.android.com/apk/res/android" android:才能layout_width=癿atch_parent" android:才能layout_height=癅dimen/height216px" 祝辞才能; & lt; TextView才能 ,,,android: layout_width=癿atch_parent" ,,,android: layout_height=?00 dp" ,,,android:重力=癱enter" ,,,android:文本=癰ottom_sheet_peek",/比; & lt;/RelativeLayout>
3代码实现
//底部抽屉栏展示地址 ,,,mBehavior =, BottomSheetBehavior.from (mRelativeLayout); , ,,,mBehavior.setBottomSheetCallback (new BottomSheetBehavior.BottomSheetCallback (), { ,,,,@Override ,,,,,public void onstatechange (@NonNull View  bottomSheet,, @BottomSheetBehavior.State int newState), { ,,,,,,,String state =,“null"; ,,,,,,,switch (newState), { ,,,,,,,,,case 1: ,,,,,,,,,,,state =,“STATE_DRAGGING"//过渡状态此时用户正在向上或者向下拖动bottom 表 ,,,,,,,,,,,休息; ,,,,,,,,,case 2: ,,,,,,,,,,,state =,“STATE_SETTLING",,//,视图从脱离手指自由滑动到最终停下的这一小段时间 ,,,,,,,,,,,休息; ,,,,,,,,,case 3: ,,,,,,,,,,,state =,“STATE_EXPANDED",,//处于完全展开的状态 , ,,,,,,,,,,,休息; ,,,,,,,,,case 4: ,,,,,,,,,,,state =,“STATE_COLLAPSED",,//默认的折叠状态 ,,,,,,,,,,,休息; ,,,,,,,,,case 5: ,,,,,,,,,,,state =,“STATE_HIDDEN",,//下滑动完全隐藏,bottom 表 ,,,,,,,,,,,休息; ,,,,,,,} , ,,,,,} , ,,,,@Override ,,,,,public void onSlide (@NonNull View  bottomSheet,, float slideOffset), { null null null null null null null怎么在Android中使用BottomSheet实现一根根可拉伸控件