最后用Android中的AnimationDrawable反向动画

时间:2016-08-17 11:54:47

标签: android animation drawable

如何在Android中反转AnimationDrawable。

为了优化我的应用,我想在动画结束时将其动画。

这是我的代码:

    AnimationDrawable animation = new AnimationDrawable();
    animation.addFrame(getResources().getDrawable(R.drawable.ball1), 100);
    animation.addFrame(getResources().getDrawable(R.drawable.ball2), 100);
    animation.addFrame(getResources().getDrawable(R.drawable.ball3), 100);
    animation.addFrame(getResources().getDrawable(R.drawable.ball4), 100);
    animation.addFrame(getResources().getDrawable(R.drawable.ball5), 100);
    animation.addFrame(getResources().getDrawable(R.drawable.ball6), 100);
    animation.addFrame(getResources().getDrawable(R.drawable.ball5), 100);
    animation.addFrame(getResources().getDrawable(R.drawable.ball4), 100);
    animation.addFrame(getResources().getDrawable(R.drawable.ball3), 100);
    animation.addFrame(getResources().getDrawable(R.drawable.ball2), 100);
    animation.addFrame(getResources().getDrawable(R.drawable.ball1), 100);
    animation.setOneShot(false);

    ImageView imageAnim =  (ImageView) findViewById(R.id.image_view1);
    imageAnim.setBackgroundDrawable(animation);

    animation.start();

我希望动画改变方向而不是加载5个新图像,但我没有找到如何做到这一点。

感谢

巴尔

1 个答案:

答案 0 :(得分:-1)

添加此插补器

 public class ReverseInterpolator implements Interpolator {
  @Override
  public float getInterpolation(float paramFloat) {
    return Math.abs(paramFloat -1f);
  }
 }


 animation.setInterpolator(new ReverseInterpolator());