Splash Screen不会被隐藏

时间:2014-10-30 18:38:50

标签: android screen splash

我正在尝试向我的应用程序添加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);

    }
}

抱歉我的英文。

2 个答案:

答案 0 :(得分: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.

答案 1 :(得分:0)

动画后使用此功能......

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