我已經嘗試了幾種基於這裏的答案,如animation.setRepeatCount(Animation.INFINITE)在我的動畫循環;或者android:repeatcount =「infinite」在anim.xml文件中.even在java上嘗試了while(true)循環,但似乎沒有任何工作。Android繼續循環動畫
<?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();
};
我沒有得到什麼似乎沒有工作? –
我的意思是連續循環。它只有一次動畫,然後沒有任何反應。我想保持它動畫.. – hpa