gpt4 book ai didi

android - 为帧动画设置监听器

转载 作者:行者123 更新时间:2023-11-29 18:04:15 24 4
gpt4 key购买 nike

我有以下 XML 文件来定义我的帧动画:

<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/youme_blink_frame_0000" android:duration="40" />
<item android:drawable="@drawable/youme_blink_frame_0001" android:duration="40" />
<item android:drawable="@drawable/youme_blink_frame_0002" android:duration="40" />
<item android:drawable="@drawable/youme_blink_frame_0003" android:duration="40" />
<item android:drawable="@drawable/youme_blink_frame_0004" android:duration="40" />
<item android:drawable="@drawable/youme_blink_frame_0005" android:duration="40" />
<item android:drawable="@drawable/youme_blink_frame_0006" android:duration="40" />
<item android:drawable="@drawable/youme_blink_frame_0007" android:duration="40" />
<item android:drawable="@drawable/youme_blink_frame_0008" android:duration="40" />
<item android:drawable="@drawable/youme_blink_frame_0009" android:duration="40" />
<item android:drawable="@drawable/youme_blink_frame_0010" android:duration="40" />
</animation-list>

然后我有以下代码:

    Animation mAnim = AnimationUtils.loadAnimation(this, R.anim.blink);
mAnim.setAnimationListener(this);

ImageView img = (ImageView)findViewById(R.id.animationImage);
img.clearAnimation();
img.setAnimation(mAnim);
img.startAnimation(mAnim);

此代码生成错误“未找到动画文件”的异常。是帧动画不认为是动画还是我做错了什么?

谢谢, 西蒙

最佳答案

逐帧动画是 AnimationDrawable 而不是 Animation。你所做的是将它用作动画,这就是异常的原因没有具有该名称的动画文件有可绘制文件。使用 AnimationDrawable 使用此代码 fragment

// Load the ImageView that will host the animation and
// set its background to our AnimationDrawable XML resource.
ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
img.setBackgroundResource(R.drawable.spin_animation);

// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();

// Start the animation (looped playback by default).
frameAnimation.start();

关于AnimationDrawable的更多信息请引用documentation

关于android - 为帧动画设置监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14187140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com