【发布时间】:2014-03-22 15:48:37
【问题描述】:
我想在加载主要活动时制作启动画面。
所以,我添加了 Splash 活动。
package com.originerd.tau;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
public class Splash extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Thread logoTimer = new Thread(){
@Override
public void run() {
// TODO Auto-generated method stub
try {
Intent i = new Intent(Splash.this, Main.class);
startActivity(i);
sleep(4500);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
finally{
finish();
}
}
};
logoTimer.start();
}
}
和activity_splash xml。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash" />
但是当我执行它时,屏幕只显示黑色窗口并在 3 秒后显示主要活动。我认为这是因为启动活动的图像加载时间。所以我在Intent i = new Intent(Splash.this, Main.class); 行之前添加了sleep(1000);。它有效,但我认为这不是一个好的解决方案。
我想知道在这种情况下什么是好的解决方案。目的是在主要活动准备内容时显示图像(大约需要 3 秒)。如果有任何解决方案(加载图像)而不是启动画面,请告诉我。
【问题讨论】:
标签: android splash-screen