我尝试制作动画启动画面,问题是在启动画面后没有显示MainActivity。我添加了一些代码,但它会让它崩溃。你能帮我吗。 在Splash Screen Activity的代码下面
public class SplashScreenActivity extends Activity {
public void onAttachedToWindow() {
super.onAttachedToWindow();
Window window = getWindow();
window.setFormat(PixelFormat.RGBA_8888);
}
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
CountDown _tik;
_tik=new CountDown(3000,3000,this,MainActivity.class);// It delay th
screen for 3 second and after that switch to my MainActivity
_tik.start();
StartAnimations();
}
private void StartAnimations() {
Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
anim.reset();
LinearLayout l=(LinearLayout) findViewById(R.id.lin_lay);
l.clearAnimation();
l.startAnimation(anim);
anim = AnimationUtils.loadAnimation(this, R.anim.translate);
anim.reset();
ImageView iv = (ImageView) findViewById(R.id.logo);
iv.clearAnimation();
iv.startAnimation(anim);
}
在CountDown代码下面
public class CountDown extends CountDownTimer{
private Activity _act;
private Class _cls;
public CountDown(long millisInFuture, long countDownInterval,Activity act,Class cls) {
super(millisInFuture, countDownInterval);
_act=act;
_cls=cls;
}
@Override
public void onFinish() {
_act.startActivity(new Intent(_act,_cls));
_act.finish();
}
@Override
public void onTick(long millisUntilFinished) {
}
最后一个是我想在启动画面后显示的活动
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
请注意。动画工作很好。只有问题是当我想要在Splash Screen之后获得MainActivity时。