如果我不设置 peekHeight,BottomSheetBehavior 不可拖动

BottomSheetBehavior not draggable if i do not set peekHeight

在我的应用程序中,我有一个底部 sheet 和一个使它成为 collapse/expand 的按钮。

如果未设置peekHeight底部sheet不可拖动且不会折叠,它始终可见。

代码如下:

        View bottomSheet = findViewById(R.id.bottom_sheet1);
        mBottomSheetBehavior1 = BottomSheetBehavior.from(bottomSheet);

        mBottomSheetBehavior1.setPeekHeight(0); //IF I OMIT THIS, IT DOES NOT WORK

        mButton1 = (Button) findViewById(R.id.button_1);
        mButton1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(mBottomSheetBehavior1.getState() != BottomSheetBehavior.STATE_EXPANDED) {
                    mBottomSheetBehavior1.setState(BottomSheetBehavior.STATE_EXPANDED);
                    mButton1.setText("Collapse 1");
                }
                else {
                    mBottomSheetBehavior1.setState(BottomSheetBehavior.STATE_COLLAPSED);
                    mButton1.setText("Expand 1");
                }
            }
        });

怎么了?

默认情况下,BottomSheetBehavior 不是 hideable

您必须明确说明您希望该行为可隐藏:


    bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
    bottomSheetBehavior.setHideable(true);