美文网首页
1.Frame Animation 逐帧动画

1.Frame Animation 逐帧动画

作者: Varmin | 来源:发表于2017-05-30 01:25 被阅读0次
加载动画/渐变动画等,用途也是挺多的。

资料1
资料2

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="true">//false 一直重复执行,true执行一次。
    <item
        android:duration="200"
        android:drawable="@drawable/frame_anim_1"/>
    <item
        android:duration="200"
        android:drawable="@drawable/frame_anim_2"/>
    <item
        android:duration="200"
        android:drawable="@drawable/frame_anim_3"/>
    <item
        android:duration="200"
        android:drawable="@drawable/frame_anim_4"/>
    <item
        android:duration="200"
        android:drawable="@drawable/frame_anim_4"/>
</animation-list>
ImageView mImageViewFilling = (ImageView) findViewById(R.id.imageview_animation_list_filling);
((AnimationDrawable) mImageViewFilling.getBackground()).start();
  代码中添加
  rocketAnimation = new AnimationDrawable();
  rocketAnimation.addFrame(getResources().getDrawable(R.drawable.rocket_thrust1, 200);
  rocketAnimation.addFrame(getResources().getDrawable(R.drawable.rocket_thrust2, 200);
  rocketAnimation.addFrame(getResources().getDrawable(R.drawable.rocket_thrust3, 200);
  rocketImage.setBackground(rocketAnimation);  
  • 需要注意的是,动画的启动需要在view和window建立连接后才可以绘制,比如上面代码是在用户触摸后启动。如果我们需要打开界面就启动动画的话,则可以在Activity的onWindowFocusChanged()方法中启动。
Animated-Selector 21以上,需要适配。

相关文章

网友评论

      本文标题:1.Frame Animation 逐帧动画

      本文链接:https://www.haomeiwen.com/subject/hrwlfxtx.html