hust201010701/XDanmuku

请问怎么循环轮播呢?

Opened this issue · 1 comments

如果只有20条数据,怎么循环

可以使用类似代码,应该就可以了:

new Thread() {
        @Override
        public void run() {
            super.run();
            while (true) {
                for (int i = 0; i < 20; i++) {
                    Message msg = new Message();
                    msg.what = 1;
                    msg.arg1 = i;
                    handler.sendMessage(msg);
                    try {
                        // 延时1秒
                        sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }.start();
// 需要把20条内容add进去
    List<String> list =new ArrayList<>();

    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1) {
                addDanmu(list.get(msg.arg1));
            }
        }
    };

    public void addDanmu(String content) {
        DanmuEntity danmuEntity = new DanmuEntity();
        danmuEntity.setContent(content);
        danmuContainerView.addDanmu(danmuEntity);
    }