翻看了一下 BottomSheetBehavior 的源码
if (this.peekHeightAuto) {
if (this.peekHeightMin == 0) {
this.peekHeightMin = parent.getResources().getDimensionPixelSize(dimen.design_bottom_sheet_peek_height_min);
}
this.lastPeekHeight = Math.max(this.peekHeightMin, this.parentHeight - parent.getWidth() * 9 / 16);
} else {
this.lastPeekHeight = this.peekHeight;
}
private View wrapInBottomSheet(int layoutResId, View view, LayoutParams params) {
FrameLayout container = (FrameLayout)View.inflate(this.getContext(), layout.design_bottom_sheet_dialog, (ViewGroup)null);
CoordinatorLayout coordinator = (CoordinatorLayout)container.findViewById(id.coordinator);
if (layoutResId != 0 && view == null) {
view = this.getLayoutInflater().inflate(layoutResId, coordinator, false);
}
FrameLayout bottomSheet = (FrameLayout)coordinator.findViewById(id.design_bottom_sheet);
this.behavior = BottomSheetBehavior.from(bottomSheet);
this.behavior.setBottomSheetCallback(this.bottomSheetCallback);
this.behavior.setHideable(this.cancelable);
if (params == null) {
bottomSheet.addView(view);
} else {
bottomSheet.addView(view, params);
}
............
}
通过源码发现,拿到BottomSheetBehavior就可以很方便设置peekHight,设置state
BottomSheetBehavior mBehavior = BottomSheetBehavior.from((View)getView().getParent());
mBehavior.setPeekHeight(1000); //设置默认高度,折叠态
//设置默认全屏
mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED) //设置为展开状态
mBehavior.setKipCollapsed(true) //设置下滑跳过折叠态
设置默认全屏
给layout xml中设置 minHeight (大于屏幕高度)
BottomSheetBehavior mBehavior = BottomSheetBehavior.from((View)getView().getParent());
mBehavior.skipCollapsed = true
mBehavior.state=BottomSheetBehavior.STATE_EXPANDED;
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。