我正在 android 2.1 中编写启动画面。我希望在初始屏幕上按顺序显示 20 张 png 图像。我尝试使用动画列表,但无法做到。
这是我的代码。现在,有一个名为 firstLoadingImage.png 的图像。仅显示 5000 毫秒。然后 myappactivity 开始。但是,在这段等待时间内,我无法更新图像源。你觉得我怎么能做到这一点?
闪屏活动
package myapp.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
public class SplashScreenActivity extends Activity {
protected boolean _active = true;
protected int _splashTime = 5000; // time to display the splash screen in ms
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
Thread splashTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while(_active && (waited < _splashTime)) {
sleep(100);
if(_active) {
waited += 100;
}
}
} catch(InterruptedException e) {
// do nothing
} finally {
finish();
startActivity(new Intent(SplashScreenActivity.this, MyAppActivity.class));
stop();
}
}
};
splashTread.start();
}
}
闪屏.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/linearLayout"
android:background="@drawable/loading_screen_background" >
<ImageView
android:id="@+id/firstLoadingImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/loading100" />
</LinearLayout>