【问题标题】:Splash Screen won't hide启动画面不会隐藏
【发布时间】:2014-10-30 18:38:50
【问题描述】:

我正在尝试将 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);

    }
}

对不起我的英语。

【问题讨论】:

  • 您在哪里完成启动 Activity 并开始主 Activity?
  • 所以我猜你只是将启动画面用于动画。在该动画之后,您需要完成初始屏幕活动并启动您的主要活动。除非您启动主要活动,否则它不会加载。
  • @Rohit5k2 知道如何开始我的主要活动吗?
  • @jvrodrigues 已经回答了...如果您不想拖延,请查看我的回答。

标签: android screen splash-screen


【解决方案1】:

在你的动画之后使用它...

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

【讨论】:

  • 您的代码让我直接进入应用程序,就像跳过 SplashScreenActivity 一样。我应该添加一个计时器吗?
  • 它没有跳过启动画面,但速度太快了。在您想要显示初始屏幕的持续时间内使用计时器。
  • 似乎我所要做的就是添加一个计时器,感谢您的帮助:D
【解决方案2】:

将此添加到您的 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.

【讨论】:

  • (MainActivity.class, this); ,java.lang.Runnable)
  • 糟糕!我在那里犯了一个错误。编辑它现在尝试。
  • "无法解析构造函数 Intent (java.lang.Class,
  • 时间不早了,我很累。 .. 尝试最后一次编辑。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-04
相关资源
最近更新 更多