0

我试图做一个动画启动画面,问题是在启动画面之后没有显示 MainActivity。我添加了一些代码,但它使它崩溃。你能帮我吗。在启动屏幕活动的代码下方

   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);



   }

倒计时代码下方

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;
}

请注意。动画效果很好。唯一的问题是当我试图在启动画面后获取 MainActivity 时。

4

1 回答 1

2

您是否错过了设置动画侦听器?我认为你必须从动画监听器的 onAnimationEnd 方法调用你的主要活动。可能这会帮助你问题 会帮助你。

于 2013-04-17T03:27:24.167 回答