Android帧动画无效解决方案
程序员文章站
2024-03-23 23:11:46
...
记录一下今天应用帧动画的时候莫名无效的问题,经过一番查找解决,终于是搞定了。
首先是帧动画的Drawable文件,注意:这里的图片资源文件必须放在res/Drawable目录下
<?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/image1_1" android:duration="1000"/>
<item android:drawable="@drawable/image1_2" android:duration="1000"/>
</animation-list>
紧接着,ImageView设置好background属性
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/anima_jiaojing" />
往常,这样就能实现动画效果了,但是今天莫名其妙没有动画效果,一经查找发现
需要加上这么两行些代码,并且这两行代码必须加在onWindowFocusChanged里面
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
//解决帧动画没效果、不能在onCreate方法中调用,由于onCreate时Drawable未完成绘制
AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();
animationDrawable.start();
}
推荐阅读
-
Android帧动画无效解决方案
-
Android动画之View(补间)动画和帧动画
-
关于Android HTML5 audio autoplay无效问题的解决方案
-
关于Android HTML5 audio autoplay无效问题的解决方案
-
Android动画之逐帧动画(Frame Animation)基础学习
-
Android中Listview点击item不变颜色及设置listselector 无效的解决方案
-
Android 动画(View动画,帧动画,属性动画)详细介绍
-
Android动画之逐帧动画(Frame Animation)基础学习
-
Android中Listview点击item不变颜色及设置listselector 无效的解决方案
-
Android帧动画、补间动画、属性动画用法详解