2014-10-30 79 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