2013-04-17 150 views
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時。

+0

把錯誤日誌請 – stinepike

回答

2

您是否想要設置動畫偵聽器?我認爲你必須從動畫偵聽器的onAnimationEnd方法中調用你的主要活動。可能這會幫助你Question 會幫助你。