【问题标题】:is there a way to slow down translate animation while its being executed?有没有办法在执行翻译动画时减慢它的速度?
【发布时间】:2017-05-20 22:55:56
【问题描述】:

如何控制动画的速度?翻译动画从底部到顶部,我想在动画执行期间放慢动画速度。我怎样才能做到这一点?这是我所拥有的:

public void SlideToAbove() {

    Animation slide = null;
    slide = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f, Animation.RELATIVE_TO_SELF, 0.0f);

    slide.setDuration(300);
    slide.setFillAfter(true);
    slide.setFillEnabled(true);
    toolBar.startAnimation(slide);

    final Animation finalSlide = slide;
    slide.setAnimationListener(new Animation.AnimationListener() {


        public void onAnimationStart(Animation animation) {
        }


        public void onAnimationRepeat(Animation animation) {
        }


        public void onAnimationEnd(Animation animation) {


            CoordinatorLayout.LayoutParams lp = new CoordinatorLayout.LayoutParams(
                    toolBar.getWidth(), toolBar.getHeight());
            lp.setMargins(0, 0, 0, 0);
            appBarLayout.setLayoutParams(lp);
            finalSlide.setFillAfter(true);

        }

    });

【问题讨论】:

    标签: java android android-animation android-coordinatorlayout


    【解决方案1】:

    试试这个,

    slide =new TranslateAnimation(-100f, 0f, 0f, 0f);
    slide.setDuration(600);
    

    【讨论】:

    • 如果你想让这个速度最慢,可以添加更多。
    • 我的意思是如何减慢底部到达顶部的时间。例如,当用户点击动画开始时,需要在 4 秒内从底部到达顶部。
    • 幻灯片 =new TranslateAnimation(-100f, 0f, 0f, 0f);主要是持续时间有帮助,但你可以试试这个
    猜你喜欢
    • 2020-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多