java开启多线程/鸿蒙OS开启多线程/计时器案例 原创
BLUESKYHOST
发布于 2021-3-17 16:55
浏览
1收藏
/**
开启动画
*/
private void start(Context context,DirectionalLayout directionalLayout) {
List<Integer> getid = getid();
Image image1 = new Image(context);
image1.setScaleMode(Image.ScaleMode.INSIDE);
image1.setPixelMap(ResourceTable.Media_gifloading1);
directionalLayout.addComponent(image1);
//开启串行任务
context.createSerialTaskDispatcher("", TaskPriority.DEFAULT).asyncDispatch(new Runnable() {
@Override
public void run() {
while (true) {//无限循环
try {
for (int i =0; i < getid.size() ; i++) {
Thread.sleep(1*1000L);//睡一秒
int index=i;
context.getUITaskDispatcher().asyncDispatch(new Runnable() {//开启UI专有线程更新界面
@Override
public void run() {
// directionalLayout.removeAllComponents();
directionalLayout.removeComponentAt(0);
Image image1 = new Image(context);
image1.setScaleMode(Image.ScaleMode.INSIDE);
image1.setPixelMap(getid.get(index));
System.out.println("getid.get(index)"+getid.get(index)+index);
directionalLayout.addComponent(image1);
}
});
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
}
©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
标签
赞
1
收藏 1
回复
相关推荐
好家伙,一言不合甩代码😂
咋了你还打算我干什么
hhhh~