如题。具体的问题:我给动画对象加载了10张图片(图片都不相同),使用该动画时通过AnimationDrawable的函数getNumberOfFrames()可以取得动画的帧数为10,将这个动画start后,通过AnimationDrawable的函数getCurrent()可以获得当前图片的引用,通过取得的图片对象的哈希码得知:显示该动画时就只停留在第一帧上不动了。谁遇到或知道怎么解决,请指教。
解决方案 »
- 有C#基础,初学 android,需要JAVA哪方面的基础知识?
- android-ndk-r8c 调试问题
- Android中,OOM错误。求助高手
- 求助:橡皮筋效果,类似于愤怒的小鸟中的弹弓。。
- android activity以对话框的方式显示,如何做成仿windwos关机的效果?
- 导入com.google.android.maps.MapView问题,新手
- android使用zxing进行条码识别解析图片的算法有人知道没???
- 大家如何看一个大程序的代码?
- sencha touch 做的项目打包到 Android ,在 4.0 + 机器上,输入框 焦点时 有黄色边框,怎么去掉
- 本人大学生,想开发一款应用,目前只有想法,想找一些会做应用的朋友一起
- Launcher修改问题请教
- 请教android如何用MediaRecorder录制手机播放的声音
<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();
}
});
哪位高手给了你一个范例,定义了3个组件 Button ImageView 和AnimationDrawable,然后通过监听 按钮的动作 来 start() 动画。
这个网页的内容说的是:AnimationDrawable不能在onResume()中start()的解决方法。
其中Romain Guy 提到的解决方案是:将AnimationDrawable以setImageDrawable()加载,而不是以setBackgroundDrawable()方式加载。
但是我试了试,不清楚是什么原因还是没有解决。
以下是对我提出的问题的补充:
我是在handler中调用的动画的start()方法,handler中的方法执行时在onResume()执行期间。
如果谁遇到过这个问题或知道如何解决,请指点我一下。
谢谢。