我正在android 2.1中編寫啓動畫面。我想要在啓動屏幕上按順序顯示20個PNG圖像。我試圖使用動畫列表,但無法做到這一點。在啓動畫面中逐幀動畫 - Android 2.1
這是我的代碼。現在,有一個名爲firstLoadingImage.png的圖像。只顯示5000ms。然後,myappactivity開始。但是,在這段等待時間內,我無法設法更新圖像源。你覺得我能做到這一點?
SplashScreenActivity
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();
}
}
splashscreen.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>