android – 如何设置BottomSheet完整父级的高度?

前端之家收集整理的这篇文章主要介绍了android – 如何设置BottomSheet完整父级的高度?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我试图在点击按钮上使用android-support-library 23.2调用BottomSheet.它工作正常,但没有采取全高度.它位于AppBarLayout下方.我在Android Documentation没有找到任何解决方

这是我的屏幕布局

enter image description here

enter image description here

这是我的代码.

activity_main.xml中

MainActivity.java

View bottomSheet;
private BottomSheetDialog mBottomSheetDialog;

private void initView(){
         /*
        Bottom Sheet Initialization
         */
        CoordinatorLayout coordinatorLayout = (CoordinatorLayout)findViewById(R.id.main_content);
        // The View with the BottomSheetBehavior
        bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet);
        behavior = BottomSheetBehavior.from(bottomSheet);
//        behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
        behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet,int newState) {
                // React to state change
                CommonMethods.getInstance().e("onStateChanged","onStateChanged:" + newState);
                if (newState == BottomSheetBehavior.STATE_EXPANDED) {
                    fab.setVisibility(View.GONE);
                } else {
                    fab.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void onSlide(@NonNull View bottomSheet,float slideOffset) {
                // React to dragging events
                CommonMethods.getInstance().e("onSlide","onSlide");
            }
        });

        behavior.setPeekHeight(100);

    }

点击事件代码

@Override
    public void onShareClick() {
        if (behavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
            behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
        }
        if(mBottomSheetDialog==null){
            mBottomSheetDialog = new BottomSheetDialog(this);
            View view = getLayoutInflater().inflate(R.layout.layout_bottomsheet,null);
            mBottomSheetDialog.setContentView(view);
        }

        mBottomSheetDialog.show();
        mBottomSheetDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                mBottomSheetDialog = null;
            }
        });
    }
最佳答案
更换

behavior.setPeekHeight(100);

behavior.setPeekHeight(screenUtils.getHeight());

解决你的问题.

原文链接:https://www.f2er.com/android/429956.html

猜你在找的Android相关文章