安卓图像切换器 : switch images periodically?

标签 android loops timer imageswitcher

我正在使用带有 TouchListener 的 ImageSwitcher 来更改数组中的图像。它工作正常,但我希望它每 x 秒左右切换一次图像,以便我可以添加 imageSwitcher.setImageResource(imageList[curIndex]); 到它。

有什么建议吗?

最佳答案

试试这个,

 imageSwitcher.postDelayed(new Runnable() {
            int i = 0;
            public void run() {
                imageSwitcher.setImageResource(
                    i++ % 2 == 0 ?
                        R.drawable.image1 :
                        R.drawable.mage2);
                imageSwitcher.postDelayed(this, 1000);
            }
        }, 1000);

关于安卓图像切换器 : switch images periodically?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11014729/

相关文章:

java - 仅使用 Random 而不使用 ArrayList 写入不重复的随机数

c++ - C++/MySQL 中的多个定时器

java - 如何动态获取音乐文件(或任何文件)的文件夹名称

Android Studio,构建 kotlin : wrong code generated 时出现奇怪错误

安卓工作室 : table layouts conten reformats when text is cahnged

每 X 秒的 Java 计时器

c - linux定时器是进程吗

android - 实现 Facebook 愿望 list 教程应用程序不拥有操作类型错误

python - 迭代 numpy 数组并保持维度

java - 对于(房间 r : ArrayList<Room>) returns empty Room