【问题标题】:reduce a Bottom Sheet's height减少底部工作表的高度
【发布时间】:2016-07-08 20:16:06
【问题描述】:

我知道如何change the height of a Bottom Sheet。 增加底片的高度没有问题。但是我不能用下面的代码来降低它的高度。

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

有人遇到过同样的问题吗?

【问题讨论】:

  • 因此,如果您在设置一次后更改窥视高度,它不会被应用?
  • 在设置 peekHeight 之前,您是否尝试过使用 BottomSheetBehavior.from(bottomSheet)?您可以将您的 bottomSheet 作为参数传递,然后添加您在上面使用的行

标签: android bottom-sheet


【解决方案1】:

我正在尝试做同样的事情,但我没有这样的问题。我可以轻松地增加和减少我的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);
    }

【讨论】:

    猜你喜欢
    • 2018-05-23
    • 1970-01-01
    • 2021-05-25
    • 1970-01-01
    • 2014-12-07
    • 2017-02-27
    • 2014-11-01
    • 2015-11-24
    • 1970-01-01
    相关资源
    最近更新 更多