动画启动画面后未显示主活动

时间:2013-04-17 02:19:29

标签: java android eclipse

我尝试制作动画启动画面,问题是在启动画面后没有显示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时。

1 个答案:

答案 0 :(得分:2)

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