onAnimationRepeat()方法不起作用。我已经通过logger测试了android没有访问该方法。 我做错了什么?
码
public class MainActivity extends Activity {
private TextView textView;
String animText;
private Animation fadeInAnimation;
ArrayList<String> numList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView)findViewById(R.id.animationText);
numList=new ArrayList<String>();
Random random = new Random();
int num = random.nextInt(20);
for(int i = 1; i <= num ; i++){
animText = String.valueOf(i);
numList.add(animText);
}
doFadeEffectAnimation();
}
public void doFadeEffectAnimation(){
textView = (TextView)findViewById(R.id.animationText);
textView.setTextSize(50);
fadeInAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in);
fadeInAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
for (int i = 0; i < numList.size(); i++) {
textView.setText(numList.get(i));
}
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
}
});
textView.startAnimation(fadeInAnimation);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<alpha
android:duration="2000"
android:fromAlpha="0.1"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="1.0"
android:repeatCount="2"
/>
</set>
答案 0 :(得分:-1)
尝试从onWindowFocusChanged()方法调用 doFadeEffectAnimation() ,而不是从onCreate()方法调用它...
@Override
public void onWindowFocusChanged(final boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
doFadeEffectAnimation();
}
}
希望它可能有助于解决您的问题...