安卓-BottomSheetDialogFragment高度设置
程序员文章站
2022-07-03 21:52:46
要设置Dialog的高度,重写onStart() 方法即可 private BottomSheetBehavior mBottomSheetBehavior; @Override public void onStart() { super.onStart(); Dialog dialog = getDialog(); if (dialog != null) { View bottomSh...
要设置Dialog的高度,重写onStart() 方法即可
private BottomSheetBehavior<View> mBottomSheetBehavior;
@Override
public void onStart() {
super.onStart();
Dialog dialog = getDialog();
if (dialog != null) {
View bottomSheet = dialog.findViewById(R.id.design_bottom_sheet);
bottomSheet.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
}
final View view = getView();
view.post(new Runnable() {
@Override
public void run() {
View parent = (View) view.getParent();
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) (parent).getLayoutParams();
CoordinatorLayout.Behavior behavior = params.getBehavior();
mBottomSheetBehavior = (BottomSheetBehavior) behavior;
mBottomSheetBehavior.setPeekHeight(view.getMeasuredHeight());
parent.setBackgroundColor(Color.TRANSPARENT);
}
});
}
但是,有一点很重要,layout xml各个项目必须是从上往下画的
本文地址:https://blog.csdn.net/weixin_48576311/article/details/107531581
上一篇: 使用Vue实现图片上传的三种方式
下一篇: vue路由组件按需加载的几种方法小结