2014-10-30 54 views
0

我正在嘗試將SplashScreen添加到我的應用程序中,但我遇到了一個問題: SplashScreen加載並且只是...它不會將我帶到主要活動。 這裏的SplashScreenActivity.java:初始屏幕不會隱藏

import android.app.Activity; 
import android.graphics.PixelFormat; 
import android.os.Bundle; 
import android.view.Window; 
import android.view.animation.Animation; 
import android.view.animation.AnimationUtils; 
import android.widget.ImageView; 
import android.widget.LinearLayout; 



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. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     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); 

    } 
} 

對不起,我的英語水平。

+0

你在哪裏** **完成飛濺活動和**啓動**主要活動? – 2014-10-30 18:45:01

+0

所以你只用於動畫我想你的初始屏幕。在完成該動畫之後,您需要完成啓動畫面活動並啓動主要活動。除非您啓動它,否則主要活動將不會加載。 – Rohit5k2 2014-10-30 18:51:36

+0

@ Rohit5k2關於如何開始我的主要活動的任何想法? – Alec 2014-10-30 19:42:23

回答

0

使用此動畫後...

Intent intent = new Intent(this, MainActivity.class); 
startActivity(intent); 
finish(); 
+0

您的代碼讓我直接進入應用程序,就像它跳過SplashScreenActivity一樣,我應該添加一個計時器嗎? – Alec 2014-10-31 13:10:03

+0

它不會跳過啓動畫面,但它太快了。在想要顯示啓動畫面的持續時間中使用計時器。 – Rohit5k2 2014-10-31 13:42:07

+0

似乎我所要做的就是添加一個計時器,感謝您的幫助:D – Alec 2014-10-31 14:23:11

0

添加到您的startAnimations方法的末尾:

Handler handler = new Handler(); 
handler.postDelayed(new Runnable(){ 
    @Override 
    public void run() {  
     Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class); //assuming your main ctivity is called that 
     startActivity(intent); 
     SplashScreenActivity.this.finish(); 

}, 3000); //assuming you want for the splashscreen to be displayed for 3 seconds. 
+0

(MainActivity.class,this); < - 它說:「無法解析構造函數Intent(java.lang.Class ,java.lang.Runnable) – Alec 2014-10-30 19:17:58

+0

Woops!我犯了一個錯誤,現在編輯它 – jvrodrigues 2014-10-30 19:19:20

+0

」無法解析構造函數Intent(java.lang.Class Alec 2014-10-30 19:34:02