我知道如何change the height of a Bottom Sheet 。 增加底板的高度没有问题。但是我无法使用以下代码降低其高度。
bottomSheetBehavior.setPeekHeight(peekHeight); // peekHeight < previous height
bottomSheetBehavior.setState(STATE_COLLAPSED);
有人遇到同样的问题吗?
最佳答案
我正在尝试做同样的事情,但没有遇到这样的问题。我可以轻松增加和减少 BottomSheetDialogFragment
高度。这是我的 fragment 的两个方法的代码:
private BottomSheetBehavior.BottomSheetCallback bottomSheetCallback = new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_HIDDEN) {
dismiss();
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
};
public static BottomSheetFragment newInstance() {
return new BottomSheetFragment();
}
@Override
public void setupDialog(Dialog dialog, int style) {
super.setupDialog(dialog, style);
View contentView = View.inflate(getContext(), R.layout.bottom_sheet_dialog_content_view, null);
dialog.setContentView(contentView);
CoordinatorLayout.LayoutParams layoutParams = ((CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams());
CoordinatorLayout.Behavior behavior = layoutParams.getBehavior();
if (behavior != null && behavior instanceof BottomSheetBehavior) {
((BottomSheetBehavior) behavior).setBottomSheetCallback(bottomSheetCallback);
((BottomSheetBehavior) behavior).setPeekHeight(getResources().getDimensionPixelSize(R.dimen.bottom_sheet_height) / 4);
}
initRecyclerView(contentView);
}
关于android - 减少底层的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37213531/