Android继续动画循环

时间:2016-11-10 05:01:18

标签: java android xml loops animation

我在动画中尝试了几种基于这里的答案的循环,例如animation.setRepeatCount(Animation.INFINITE);或者:anml.xml文件中的android:repeatcount =“infinite”。甚至在java上尝试了while(true)循环,但似乎都没有。

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">

<alpha
    android:fromAlpha="0.0"
    android:toAlpha="1.0"
    android:duration="3000" />

<translate
    android:fromXDelta="0.0"
    android:toXDelta="0.0"
    android:fromYDelta="0.0"
    android:toYDelta="100.0"
    android:startOffset="3000"
    android:duration="3000"
    android:repeatCount="infinite"/>

</set>

我的java是:

@Override
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    img = (ImageView) findViewById(R.id.img);
    animation = AnimationUtils.loadAnimation(this, R.anim.halloweenanim);

    img.startAnimation(animation);
    animation.setRepeatCount(Animation.INFINITE);

    //hallo.setBackgroundResource(R.drawable.halloweenimg);
    //animation2 = (AnimationDrawable) hallo.getBackground();
    //animation2 = (AnimationDrawable) img.getBackground();
    //animation.start();
};

1 个答案:

答案 0 :(得分:0)

请你试试看看它是否对你有帮助。

animation.addListener(new AnimatorListenerAdapter() {

    @Override
    public void onAnimationEnd(Animator animation) {
        super.onAnimationEnd(animation);
 Animation animation = AnimationUtils.loadAnimation(this, R.anim.halloweenanim);
 animation.setAnimationListener(this);
                img.startAnimation(animation);
    }

});
 img.startAnimation(animation);