BottomSheet动画持续时间

时间:2018-08-07 07:11:58

标签: android android-layout android-animation bottom-sheet

我将BottomSheet视图用于我的一种布局。对于一个非常特殊的情况,我需要BottomSheet的动画持续时间,该动画持续时间通过setState(...)方法在布局中滑动。应该是大约400毫秒左右,但我不希望在这种情况下没有一个“魔术”数字。

2 个答案:

答案 0 :(得分:0)

是的,您可以在底页中添加动画。 h

      // init the bottom sheet behavior
        BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(mBottomSheet);

        // change the state of the bottom sheet
        bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);

        // set callback for changes
        bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                // Called every time when the bottom sheet changes its state.
            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
                if (isAdded()) {
                    animateBottomSheetArrows(slideOffset);
                }
            }
        });
    }

    private void animateBottomSheetArrows(float slideOffset) {
        // Animate counter-clockwise
        mLeftArrow.setRotation(slideOffset * -180);
        // Animate clockwise
        mRightArrow.setRotation(slideOffset * 180); 
}

答案 1 :(得分:0)

我认为这符合您的问题:

new CountDownTimer(250, 250){
    @Override
    public void onTick(long millisUntilFinished) {

    }

    @Override
    public void onFinish() {
       bottomSheetDialog.dismiss();
    }
}.start();