首页 > 其他分享 >通过Handler实现gif图的效果

通过Handler实现gif图的效果

时间:2022-11-24 17:06:57浏览次数:31  
标签:效果 int void gif Handler Override new drawable


int[] imageIds = new int[] {
R.drawable.timer1,
R.drawable.timer2,
R.drawable.timer3,
R.drawable.timer4,
R.drawable.timer5,
R.drawable.timer6
};
int currentImageId = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageView imageView = (ImageView)findViewById(R.id.imageView);
final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if(msg.what == 0x123) {
imageView.setImageResource(imageIds[currentImageId++%imageIds.length]);
}
}
};
new Timer().schedule(new TimerTask() {

@Override
public void run() {
// TODO Auto-generated method stub
handler.sendEmptyMessage(0x123);
}
}, 0, 250);
}


标签:效果,int,void,gif,Handler,Override,new,drawable
From: https://blog.51cto.com/u_15890522/5884199

相关文章