请问,遇到了Android上动画类(AnimationDrawable)不能切换图片的问题,该如何解决。

A295623449 2011-09-03 09:29:49
如题。

具体的问题:我给动画对象加载了10张图片(图片都不相同),使用该动画时通过AnimationDrawable的函数getNumberOfFrames()可以取得动画的帧数为10,将这个动画start后,通过AnimationDrawable的函数getCurrent()可以获得当前图片的引用,通过取得的图片对象的哈希码得知:显示该动画时就只停留在第一帧上不动了。

谁遇到或知道怎么解决,请指教。


...全文
739 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
A295623449 2011-09-05
  • 打赏
  • 举报
回复
http://groups.google.com/group/android-developers/browse_thread/thread/4a8dfff18f0abd86?pli=1
这个网页的内容说的是:AnimationDrawable不能在onResume()中start()的解决方法。
其中Romain Guy 提到的解决方案是:将AnimationDrawable以setImageDrawable()加载,而不是以setBackgroundDrawable()方式加载。
但是我试了试,不清楚是什么原因还是没有解决。


以下是对我提出的问题的补充:
我是在handler中调用的动画的start()方法,handler中的方法执行时在onResume()执行期间。


如果谁遇到过这个问题或知道如何解决,请指点我一下。
谢谢。
A295623449 2011-09-05
  • 打赏
  • 举报
回复
UPUPUP。
nulls 2011-09-03
  • 打赏
  • 举报
回复

<Button android:id="@+id/framebyframe" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Frame By Frame">
</Button>
<ImageView android:id="@+id/myImage" android:layout_width="140dip"
android:layout_height="140dip">
</ImageView>

frameanimation.xml:

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/a" android:duration="200" />
<item android:drawable="@drawable/b" android:duration="200" />
<item android:drawable="@drawable/c" android:duration="200" />
<item android:drawable="@drawable/d" android:duration="200" />
<item android:drawable="@drawable/e" android:duration="200" />
<item android:drawable="@drawable/f" android:duration="200" />
<item android:drawable="@drawable/g" android:duration="200" />
<item android:drawable="@drawable/h" android:duration="200" />
<item android:drawable="@drawable/i" android:duration="200" />
</animation-list>


final ImageView myImage = (ImageView) findViewById(R.id.myImage);
Button button = (Button) findViewById(R.id.framebyframe);
button.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
myImage.setBackgroundResource(R.layout.frameanimation);
AnimationDrawable frameAnimation = (AnimationDrawable) myImage
.getBackground();
frameAnimation.start();
}
});
A295623449 2011-09-03
  • 打赏
  • 举报
回复
今天的速度怎么~~~~(>_<)~~~~ ...
A295623449 2011-09-03
  • 打赏
  • 举报
回复
A295623449 2011-09-03
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 sk811229 的回复:]

引用 4 楼 a295623449 的回复:

引用 3 楼 bluecat_crystal 的回复:

XML code

<Button android:id="@+id/framebyframe" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Fra……
[/Quote]

嗯,是的。
我不明白的是这个范例怎样解决我提的问题?
sk811229 2011-09-03
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 a295623449 的回复:]

引用 3 楼 bluecat_crystal 的回复:

XML code

<Button android:id="@+id/framebyframe" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Frame By Frame">
</Button>
……
[/Quote]

哪位高手给了你一个范例,定义了3个组件 Button ImageView 和AnimationDrawable,然后通过监听 按钮的动作 来 start() 动画。
A295623449 2011-09-03
  • 打赏
  • 举报
回复
UPUPUP
A295623449 2011-09-03
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 bluecat_crystal 的回复:]

XML code

<Button android:id="@+id/framebyframe" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Frame By Frame">
</Button>
<ImageView andr……
[/Quote]
谢谢你,但是我不知道你的回答怎么解决我提的问题。
是否可以说明一下?

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧