有没有办法在执行时减慢翻译动画的速度?

时间:2017-01-06 07:50:41

标签: java android android-animation android-coordinatorlayout

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

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

        }

    });

1 个答案:

答案 0 :(得分:5)

试试这个,

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