我可以成功添加峰值高度,但是在尝试设置底部工作表的最小高度时,我无法这样做,并且整个工作表都折叠了。所以我试图让它扩展到隐藏状态,但这对我来说还不够,因为它太高了。
我主要关心的是不要隐藏底片,如果隐藏或折叠它必须重新出现并设置最小高度
请提出一些建议:
下面是我的代码:
final View bottomSheet = findViewById(R.id.bottom_sheet2);
mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
mBottomSheetBehavior.setHideable(true);
mBottomSheetBehavior.setPeekHeight(LinearLayout.LayoutParams.MATCH_PARENT);
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_EXPANDED) {
}
else if (newState == BottomSheetBehavior.STATE_HIDDEN) {
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
else if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
}
}
@Override
public void onSlide(View bottomSheet, float slideOffset) {
}
});
Run Code Online (Sandbox Code Playgroud)
野兔是我的 xml:
<android.support.v4.widget.NestedScrollView
android:id="@+id/bottom_sheet2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="45dp"
android:clipToPadding="false"
android:background="#00ffffff"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:elevation="6dp"
app:cardCornerRadius="10dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_height="wrap_content">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="#fff" …Run Code Online (Sandbox Code Playgroud)