【问题标题】:Using FrameAnimations and AnimationDrawable to display images not working使用 FrameAnimations 和 AnimationDrawable 显示图像不起作用
【发布时间】:2013-05-24 00:48:27
【问题描述】:

我有一个简单的 .xml 布局文件,其中包含一个简单的 ImageView,我想打开该文件。我决定继续使用 FrameAnimations,使用 AnimationDrawable API。

我已经设法在“drawable/file.xml”中创建了我的动画文件,代码如下:

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
    <item android:drawable="@drawable/image_010_1" android:duration="1000" />
    <item android:drawable="@drawable/image_010_2" android:duration="1000" />
</animation-list>

现在,下面是应该启动我的动画的代码:

Image1.setBackgroundResource(R.drawable.image_010);
AnimationDrawable animation = (AnimationDrawable) Image1.getBackground();
animation.start();

由于某种原因,当我运行该应用程序时,我只看到第一帧,而下一张图像在 1000 英里之后没有出现,或者根本没有出现!我究竟做错了什么?谢谢!

【问题讨论】:

    标签: android android-imageview animationdrawable


    【解决方案1】:

    所以我设法通过向我的ImageView 添加一个 Runnable 来解决这个问题:

        image.post(new Runnable() {
    
            @Override
            public void run() {
                // TODO Auto-generated method stub
                animation.start();
            }
        });
    

    【讨论】:

      猜你喜欢
      • 2023-04-04
      • 2010-10-08
      • 2020-09-19
      • 1970-01-01
      • 2012-11-01
      • 1970-01-01
      • 2019-12-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多