经历过几次这样的问题了。设置好了动画之后,动画不执行。如下代码:
setFullScreen();
View view = LViewHelper.getView(R.layout.splash);
setContentView(R.layout.splash);
AlphaAnimation aa = new AlphaAnimation(0.1f, 1.0f);
aa.setDuration(2000);
view.startAnimation(aa);
aa.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}
});
找原因,找了半天找不到,动画就是不执行。经过反复的测试,才发现了问题,就是view的重复问题,只要把需要动画的view加载到界面中,代码如下:
setFullScreen();
View view = LViewHelper.getView(R.layout.splash);
setContentView(view);
AlphaAnimation aa = new AlphaAnimation(0.1f, 1.0f);
aa.setDuration(2000);
view.startAnimation(aa);
aa.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}
});
原来的代码,只是初始化了一个带动画的view,而并没有把view显示到界面上,这样就解决了这个问题。
时间: 2024-11-12 11:44:34