-2

我在我的 Android 应用程序中实现了启动画面。

在那个初始屏幕中,我希望有 3 个动态显示的图像,一个接一个,中间有一个设定的延迟时间。

我怎么能做这样的事情?

4

1 回答 1

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
    }
};
}
于 2012-07-14T06:04:31.327 回答