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.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
标签
1
收藏 1
回复
举报
1
3
1
3条回复
按时间正序
/
按时间倒序
卫斯理
卫斯理

好家伙,一言不合甩代码😂

回复
2021-3-17 18:21:51
BLUESKYHOST
BLUESKYHOST 回复了 卫斯理
好家伙,一言不合甩代码😂

咋了你还打算我干什么

回复
2021-3-18 16:25:49
SummerRic
SummerRic 回复了 BLUESKYHOST
咋了你还打算我干什么

hhhh~

回复
2021-4-13 15:24:54


回复
    相关推荐