我尝试不要在整个屏幕上填充BottomSheet,但在展开时留出一些空间。这是我的代码,onExpand填充整个屏幕。
bottomSheetBehavior = BottomSheetBehavior.from(bottomLayout);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
switch (newState) {
case BottomSheetBehavior.STATE_DRAGGING:
Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_DRAGGING");
break;
case BottomSheetBehavior.STATE_SETTLING:
Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_SETTLING");
break;
case BottomSheetBehavior.STATE_EXPANDED:
Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_EXPANDED");
break;
case BottomSheetBehavior.STATE_COLLAPSED:
Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_COLLAPSED");
break;
case BottomSheetBehavior.STATE_HIDDEN:
Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_HIDDEN");
break;
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
Log.i("BottomSheetCallback", "slideOffset: " + slideOffset);
boolean drawer = getSupportFragmentManager().getBackStackEntryCount() == 0;
ObjectAnimator.ofFloat(drawerArrow, "progress", drawer ? 0 : 1).start();
}
});
bottomLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.v(TAG, "ONCLickListner");
if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
Log.v(TAG,"state expand");
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
} else {
Log.v(TAG,"state collapse");
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
}
});
你能否解决我的问题并提出一种方法,使底片不要占据整个屏幕,但是在展开时留下一些空间。 感谢
答案 0 :(得分:1)
一个简单的技巧就是这样做的。我现在无法阻止底页全屏显示,所以我有一个透明的所需大小的视图,并将其添加到bottomSheetLayout解决了我的问题
<View
android:layout_width="match_parent"
android:id="@+id/spaccer"
android:layout_height="28dp"
android:background="@android:color/transparent"
android:alpha="0.6"/>