前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >给BottomSheetDialog 设置默认高度,全屏显示

给BottomSheetDialog 设置默认高度,全屏显示

原创
作者头像
用户5584592
修改2021-05-31 10:17:45
5.5K0
修改2021-05-31 10:17:45
举报
文章被收录于专栏:android代码

翻看了一下 BottomSheetBehavior 的源码

代码语言:javascript
复制
	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;
        }
代码语言:java
复制
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

代码语言:javascript
复制
BottomSheetBehavior mBehavior = BottomSheetBehavior.from((View)getView().getParent());
mBehavior.setPeekHeight(1000); //设置默认高度,折叠态

//设置默认全屏
mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED) //设置为展开状态
mBehavior.setKipCollapsed(true)  //设置下滑跳过折叠态

设置默认全屏

代码语言:javascript
复制
给layout xml中设置 minHeight   (大于屏幕高度)
BottomSheetBehavior mBehavior = BottomSheetBehavior.from((View)getView().getParent());
mBehavior.skipCollapsed = true
mBehavior.state=BottomSheetBehavior.STATE_EXPANDED;

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档