视频直播源码,三段式(抽屉式)底部弹窗BottomSheet
自定义View
继承CoordinatorLayout
/**
* Created by zGui on 2022/7/11.
* 三段式底部弹窗
*/
class ThreeBottomSheet : CoordinatorLayout {
private var mBinding: IncludeBottomSheetBinding
constructor(context: Context) : this(context, null)
constructor(context: Context, attributeSet: AttributeSet?) : this(context, attributeSet, 0)
constructor(context: Context, attributeSet: AttributeSet?, defStyle: Int) : super(
context,
attributeSet,
defStyle
) {
mBinding = DataBindingUtil.inflate(
LayoutInflater.from(context),
R.layout.include_bottom_sheet, this, true
)
val bottomSheetBehavior: BottomSheetBehavior<View> = BottomSheetBehavior.from<View>(mBinding.bottomSheet)
//上拉框状态监听
bottomSheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
//监听状态改变
override fun onStateChanged(bottomSheet: View, newState: Int) {
// when (newState) {
// BottomSheetBehavior.STATE_DRAGGING -> "STATE_DRAGGING" //过渡状态此时用户正在向上或者向下拖动bottom sheet
// BottomSheetBehavior.STATE_SETTLING -> "STATE_SETTLING" // 视图从脱离手指自由滑动到最终停下的这一小段时间
// BottomSheetBehavior.STATE_EXPANDED -> "STATE_EXPANDED" //处于完全展开的状态
// BottomSheetBehavior.STATE_HALF_EXPANDED -> "STATE_EXPANDED" //处于中间的状态
// BottomSheetBehavior.STATE_COLLAPSED -> "STATE_COLLAPSED" //默认的折叠状态
// BottomSheetBehavior.STATE_HIDDEN -> "STATE_HIDDEN" //下滑动完全隐藏 bottom sheet
// }
}
//监听滑动的过程
override fun onSlide(@NonNull bottomSheet: View, slideOffset: Float) {
}
})
bottomSheetBehavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED
}
}
布局文件
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<import type="android.view.View"/>
</data>
<LinearLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:behavior_hideable="false"
app:behavior_peekHeight="200dp"
app:behavior_fitToContents="false"
app:behavior_halfExpandedRatio="0.55"
app:layout_behavior="@string/bottom_sheet_behavior">
...
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/dp_64"
/>
</LinearLayout>
</layout>
以上就是 视频直播源码,三段式(抽屉式)底部弹窗BottomSheet,更多内容欢迎关注之后的文章
标签:layout,context,app,STATE,源码,BottomSheetBehavior,抽屉式,BottomSheet,android From: https://www.cnblogs.com/yunbaomengnan/p/17522770.html