在Android中,Animation有四种动画效果,并且分为Tween Animation和Frame Animation两类。
先看分类:
一、Tween Animation(补间动画)
一般我们用的就是这种。补间动画又分为AlphaAnimation(透明度转换)、RotateAnimation(旋转转换)、ScaleAnimation(缩放转换)、TranslateAnimation 位置转换(移动)。
动画效果在anim目录下的xml文件中定义,在程序中用AnimationUtils.loadAnimation(Context context,int ResourcesId)载入成Animation对象,在需要显示动画效果时,执行需要动画的View的startAnimation方法,传入Animation即可。切换Activity也可以应用动画效果,在startActivity方法后,执行overridePendingTransition方法,两个参数分别是切换前的动画效果,切换后的动画效果。
定义:
对一张图片进行一系列的变换(包括缩放、透明度、移动、旋转),对应的类是Animation;
在XML中实现动画的方法:
资源访问方式:
In Java: R.anim.filename
In XML: @[package:]anim/filename
文件位置:
res/anim/filename.xml
语法:
<?xml version="1.0" encoding="utf-8"?>
<setxmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@[package:]anim/interpolator_resource"
android:shareInterpolator=["true" | "false"] >
<alpha
android:fromAlpha="float"
android:toAlpha="float"/>
<scale
android:fromXScale="float"
android:toXScale="float"
android:fromYScale="float"
android:toYScale="float"
android:pivotX="float"
android:pivotY="float"/>
<translate
android:fromXDelta="float"
android:toXDelta="float"
android:fromYDelta="float"
android:toYDelta="float"/>
<rotate
android:fromDegrees="float"
android:toDegrees="float"
android:pivotX="float"
android:pivotY="float"/>
<set>
...
</set>
</set>
详细说明:
set节点:对应AnimationSet类