Handler消息传递机制
来源:互联网 发布:淘宝查优惠券插件 编辑:程序博客网 时间:2024/06/05 18:45
package com.android.xiong.gridlayoutTest;
import java.sql.Time;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;
public class AutoPlayActivity extends Activity {
/**
* @author zm
*/
private ImageView iv_autoplay;
//存放的图片资源数组
private int[] images = new int[] { R.drawable.gril1, R.drawable.gril2,
R.drawable.gril3, R.drawable.gril4, R.drawable.gril5,
};
//当前图片的索引
private int currentImg = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_img);
initView();
final Handler hanlder=new Handler(){
public void handleMessage(android.os.Message msg) {
if(msg.what==0x1233){
//动态的显示图片
iv_autoplay.setScaleType(ImageView.ScaleType.FIT_XY);
iv_autoplay.setImageResource(images[currentImg++%images.length]);
}
};
};
new Timer().schedule(new TimerTask() {
@Override
public void run() {
// 发送一条空消息
hanlder.sendEmptyMessage(0x1233);
}
},0, 1000);
}
private void initView() {
// 初始化View
iv_autoplay = (ImageView) findViewById(R.id.iv_autoplay);
}
}
布局文件activity_img
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/iv_autoplay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:src="@drawable/gril2" />
</LinearLayout>
效果如下图所示
0 0
- Handler消息传递机制
- Handler 消息传递机制
- Handler消息传递机制
- Handler消息传递机制
- Handler 消息传递机制
- Handler消息传递机制
- Handler消息传递机制
- Handler消息传递机制
- Handler 消息传递机制
- Handler 消息传递机制
- Handler消息传递机制
- Handler消息传递机制
- Handler消息传递机制
- Handler消息传递机制
- Handler消息传递机制
- Handler消息传递机制
- Handler消息传递机制
- Handler消息传递机制
- iOS 添加事件到系统日历中
- iOS学习(十七)Objective-C 组合
- jQuery Validate 自定义验证方法引入问题
- 链表插入排序
- java 数据类型
- Handler消息传递机制
- java 导出excel
- HDU 4856 Tunnels(BFS+状压DP)
- Java泛型
- android ViewPager在拖拽到左边和右边的时候,禁止显示黄色或者蓝色的渐变图片的解决方法
- CSS为div添加尖角样式
- java.lang.UnsupportedClassVersionError解决方法
- ubuntu采用apt-get安装软件出现依赖问题的解决方案
- Swift类中如何创建一个对外只读对内可读写的属性