(1)初始化控件
1.1在drawable创建动画explosiontext。
<?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/paly_one_new"
android:duration="300" />
<item
android:drawable="@drawable/paly_two_new"
android:duration="300" />
<item
android:drawable="@drawable/paly_three_new"
android:duration="300" />
</animation-list>
1.2xml布局里设置好src
<ImageView android:id="@+id/splash_iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="55dp" android:src="@drawable/explosiontext" />
1.3activity里初始化控件
@BindView(R.id.ddgif)
ImageView ddgif;
AnimationDrawable anim;
(2)onCreat方法里执行:
anim = (AnimationDrawable) iv.getDrawable();
ddgif.getViewTreeObserver().addOnPreDrawListener(preDrawListener);
(3)类里初始化监听
OnPreDrawListener preDrawListener =new OnPreDrawListener() {
@Override
publicboolean onPreDraw() {
anim.start();
returntrue;// 必须要有这个true返回 }
};
网友评论