The*_*neX 11 android animationdrawable
我正在关注Google提供的如何将DynamicDrawable与ImageView一起使用的示例.您可以在此处找到它:http://developer.android.com/guide/topics/graphics/drawable-animation.html
imageView.setBackgroundResource(R.drawable.animation);
AnimationDrawable animation = (AnimationDrawable)imageView.getBackground();
animation.start();
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我收到错误:
java.lang.ClassCastException: android.graphics.drawable.BitmapDrawable cannot be cast to android.graphics.drawable.AnimationDrawable
Run Code Online (Sandbox Code Playgroud)
Google似乎认为这应该可行,但是如果你不能将BitmapDrawable强制转换为AnimationDrawable,我不确定它应该如何工作?
我找到了解决这个问题的方法.
imageView.setImageDrawable(getResource().getDrawable(R.drawable.animation);
AnimationDrawable animation = (AnimationDrawable)imageView.getDrawable();
animation.start();
Run Code Online (Sandbox Code Playgroud)
我不知道为什么谷歌的文档说使用背景,但使用setImageDrawable和getDrawable工作.老实说,它会比其他方式更有意义.
| 归档时间: |
|
| 查看次数: |
10521 次 |
| 最近记录: |