我在Android应用中实现了启动画面。
在那个启动画面中,我希望有3个动态显示的图像,一个接一个,中间有一组延迟时间。
我该怎么办?
答案 0 :(得分:2)
你可以尝试这段代码,它可能对你有所帮助......
您可以在runnable1,runnable2和runnabl3 ....中设置背景图片资源。
package com.vc;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;
public class Splash extends Activity {
private final int FIRST_DELAY = 3000;
private final int SECOND_DELAY = 6000;
private final int THIRD_DELAY = 9000;
private Handler mHandler;
private ImageView mImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mImageView = (ImageView)findViewById(R.id.splash_imgeview);
mHandler = new Handler();
mHandler.postDelayed(image1Runnable, FIRST_DELAY);
mHandler.postDelayed(image2Runnable, SECOND_DELAY);
mHandler.postDelayed(image3Runnable, THIRD_DELAY);
}
Runnable image1Runnable = new Runnable() {
@Override
public void run() {
mImageView.setBackgroundResource(R.drawable.icon);//First image icon
}
};
Runnable image2Runnable = new Runnable() {
@Override
public void run() {
mImageView.setBackgroundResource(R.drawable.icon);//Second image icon
}
};
Runnable image3Runnable = new Runnable() {
@Override
public void run() {
mImageView.setBackgroundResource(R.drawable.icon);//Third image icon
}
};
}