Android 3种动画详解
ONE Goal , ONE Passion !
今天不太忙,突然想起来动画了.决定把android动画总结一下;
Android动画分为3种
第一 :逐帧(Frame)动画
逐帧动画是最容易理解的动画,它要求我们把动画过程的每张静态图片都收集起来,然后有Android来控制依次显示这些静态图片,在利用人眼”视觉延迟”的原理,给使用者造成”动画”的错觉.其实和放电影是一个道理.
1,在res文件加下建立animator文件夹,写frame.xml文件
<?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/h10"
android:duration="1000" />
<item
android:drawable="@drawable/h11"
android:duration="500" />
<item
android:drawable="@drawable/h12"
android:duration="600" />
<item
android:drawable="@drawable/h13"
android:duration="600" />
<item
android:drawable="@drawable/h14"
android:duration="600" />
<item
android:drawable="@drawable/h15"
android:duration="600" />
</animation-list>
oneshot属性: 控制动画循环 true--不循环
2,为某个需要使用的动画的ImageView设置背景为动画
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@animator/frame"/>
3,在activity中开启动画或取消
iv = (ImageView) findViewById(R.id.iv);
AnimationDrawable anim = (AnimationDrawable) iv.getBackground();
anim.start(); //开始动画
anim.stop(); //停在动画