首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android每10秒更换一次图片

Android每10秒更换一次图片
EN

Stack Overflow用户
提问于 2011-05-25 22:21:02
回答 4查看 29.8K关注 0票数 13

我正在尝试写一个非常基本的android应用程序,在屏幕上一个接一个地显示大约5张图片。我希望它在大约10秒后显示一张不同的图片。有没有人能建议我如何解决这个问题。下面我已经概述了我将寻找什么。

图1

图2

图3

图4

图5

显示全屏图片1

等待10秒

删除图片1并显示图片2

等待10秒

删除图片2并显示图片3

等待10秒

删除图片3并显示图片4

等待10秒

删除图片4并显示图片5

等待10秒

重新开始

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2011-05-25 22:28:04

您是否考虑过使用Frame Animations

您可以在包含逐帧动画的动画文件夹中指定xml,指定每个图像的持续时间和其他设置,请检查它

更新

当然,您也可以通过编程方式构建帧动画:

代码语言:javascript
复制
    AnimationDrawable animation = new AnimationDrawable();
    animation.addFrame(getResources().getDrawable(R.drawable.image1), 100);
    animation.addFrame(getResources().getDrawable(R.drawable.image2), 500);
    animation.addFrame(getResources().getDrawable(R.drawable.image3), 300);
    animation.setOneShot(false);

    ImageView imageAnim =  (ImageView) findViewById(R.id.img);
    imageAnim.setBackgroundDrawable(animation);

    // start the animation!
    animation.start()
票数 42
EN

Stack Overflow用户

发布于 2011-05-25 22:42:00

您可以使用CountDownTimer:请执行以下步骤:

1)声明一个包含图片标识的array

2)如下声明CountDownTimer

代码语言:javascript
复制
int i=0;
new CountDownTimer(10000,1000) {

                @Override
                public void onTick(long millisUntilFinished) {}

                @Override
                public void onFinish() {
                    imgView.setImageDrawable(sdk.getContext().getResources().getDrawable(array[i]));
                    i++;
                    if(i== array.length-1) i=0;
                    start();
                }
            }.start();
票数 7
EN

Stack Overflow用户

发布于 2015-04-22 23:26:13

创建blink.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/selected" android:oneshot="false">
<item android:drawable="@drawable/Picture_1" android:duration="10000" />
<item android:drawable="@drawable/Picture_2" android:duration="10000" />
<item android:drawable="@drawable/Picture_3" android:duration="10000" />
<item android:drawable="@drawable/Picture_4" android:duration="10000" />
<item android:drawable="@drawable/Picture_5" android:duration="10000" />
</animation-list>

将blink.xml放在可绘制文件夹中,并在活动代码中写下这段代码。

代码语言:javascript
复制
ImageView mImageView ;
mImageView = (ImageView)findViewById(R.id.imageView); //this is your imageView
mImageView .setImageDrawable(getResources().getDrawable( R.drawable.blink));

然后你就会得到你想要的。!

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6125936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档