无法隐藏底部表,Android

alb*_*alb 6 java android bottom-sheet

我的有问题,因为当我打开活动时它会打开,阻止视图 在此输入图像描述

我认为,这种情况会发生,因为XML属性声明的高度为350dp:

<android.support.v4.widget.NestedScrollView
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="350dp"
    android:background="?android:attr/windowBackground"
    android:clipToPadding="true"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
Run Code Online (Sandbox Code Playgroud)

问题是,我无法将该值更改为0dp,因为下次当我尝试打开,没有,因为高度为0dp,所以它不会显示任何内容.我的问题是,有没有办法宣布关闭?(我尝试将stateState设置为STATE_COLLAPSED但不起作用).Bellow是与底部工作表交互的java代码.JAVA:

View bottomSheet = findViewById( R.id.bottom_sheet );
        mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
        mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
        mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(View bottomSheet, int newState) {
                if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
                    //mBottomSheetBehavior.setPeekHeight(0);
                    //mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                    //mBottomSheetBehavior.isHideable();
                }
            }

            @Override
            public void onSlide(View bottomSheet, float slideOffset) {

            }
        });
Run Code Online (Sandbox Code Playgroud)

小智 9

写这个:

    mBottomSheetBehavior.setPeekHeight(0);
Run Code Online (Sandbox Code Playgroud)


Pie*_*lla 7

首先,您必须添加属性

app:behavior_hideable="true"
Run Code Online (Sandbox Code Playgroud)

在你的

<android.support.v4.widget.NestedScrollView
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="350dp"
    android:background="?android:attr/windowBackground"
    android:clipToPadding="true"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
Run Code Online (Sandbox Code Playgroud)

然后你可以使用隐藏底部工作表

mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN)
Run Code Online (Sandbox Code Playgroud)

并不是

mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED)
Run Code Online (Sandbox Code Playgroud)

状态COLLAPSED介于HIDDEN和EXPANDED之间,其高度必须由属性指定:

app:behavior_peekHeight="200dp"
Run Code Online (Sandbox Code Playgroud)