首页 文章

BottomSheet动画持续时间

提问于
浏览
0

我正在使用BottomSheet视图作为我的一个布局 . 对于一个非常特殊的情况,我需要BottomSheet的动画持续时间,它通过setState(...)方法在布局中滑动 . 它应该是大约400毫秒的东西,但我宁愿没有这个案例的“神奇”数字 .

1 回答

  • 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); 
    }
    

相关问题