初始屏幕不会隐藏
我正在尝试将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);
}
}
对不起,我的英语水平。
使用此动画后...
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
添加到您的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) – Alec 2014-10-30 19:17:58
Woops!我犯了一个错误,现在编辑它 – jvrodrigues 2014-10-30 19:19:20
”无法解析构造函数Intent(java.lang.Class
你在哪里** **完成飞溅活动和**启动**主要活动? – 2014-10-30 18:45:01
所以你只用于动画我想你的初始屏幕。在完成该动画之后,您需要完成启动画面活动并启动主要活动。除非您启动它,否则主要活动将不会加载。 – Rohit5k2 2014-10-30 18:51:36
@ Rohit5k2关于如何开始我的主要活动的任何想法? – Alec 2014-10-30 19:42:23