猿问

看下我写的

package com.android.testapplication;


import java.text.SimpleDateFormat;


import android.app.Activity;

import android.os.Bundle;

import android.os.Handler;

import android.util.Log;

import android.widget.ImageView;

import android.widget.ImageView.ScaleType;


public class HandlerActivity extends Activity {


private ImageView iv;

private Handler han = new Handler();

private int[] images = {R.drawable.a0, R.drawable.a1, R.drawable.b1,

R.drawable.b2};

private int index = 0;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

iv = new ImageView(this);

iv.setImageResource(R.drawable.ic_launcher);

iv.setAdjustViewBounds(true);

iv.setScaleType(ScaleType.CENTER);

setContentView(iv);

new Thread(new Runnable() {


@Override

public void run() {

han.post(new Runnable() {


@Override

public void run() {

index++;

index = index % 4;

Log.e("HandlerActivity", new SimpleDateFormat(

"yyyy-MM-dd hh:mm:ss")

.format(new java.util.Date()));

iv.setImageResource(images[index]);

han.postDelayed(this, 1000);

}

});

}

}).start();

}


}


玛马吉
浏览 1084回答 1
1回答

慕斯0983737

OH MY LADY GAGA
随时随地看视频慕课网APP

相关分类

Android
我要回答