2

我知道如何更改 Bottom Sheet 的高度。增加底片的高度没有问题。但是我不能用下面的代码降低它的高度。

bottomSheetBehavior.setPeekHeight(peekHeight); // peekHeight < previous height
bottomSheetBehavior.setState(STATE_COLLAPSED);

有人遇到同样的问题吗?

4

1 回答 1

3

我正在尝试做同样的事情,但我没有这样的问题。我可以很容易地增加和减少我的BottomSheetDialogFragment身高。这是我的片段的两种方法的代码:

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);
    }
于 2016-07-08T12:16:06.450 回答