通过对图片进行透明度,伸缩,rotation, 和移动的方式实现动画效果。通过预先定义的一组指令, 这些指令指定了图形变换的类型,出发时间,持续时间。程序沿着时间线就可以实现动画效果。
file location
res/anim/filename.xml
resource reference
in java: R.anim.filename
in XML: @anim/filename
推荐在xml中定义scale, rotate, alpha, transite. xml的根目录是single root的, root必须是<scale>,<rotate>,<translate>,<alpha>和<set>中的一个。 <set>可以 hold a group of other components include other <set>.
scale 的pivotX和pivotY表示图片中的一个点,这样图片就可以以这个点为中心进行伸缩,如果为(0,0)就表示是图片的左上定点,那么图片就向右下伸缩。pivotX和pivotY点在图片伸缩过程中remain fixed. android:fromXScale 表示开始时图片在x轴上的伸缩,1.0f表示图片大小不变。小于1.0为图片变小。
translate表示上下和(或)左右移动。如果图片起始点在(0,0), 开始translate时,如果在translate里设定移动起始点为(5,5),图片先移动到这个点再开始translate
支持三种格式 -100% ->100%: 表示a percentage relative to itself
-100%p -> 100%p表示a percentage relative to its parent
a float with no suffix 表示an absolute value
rotate的pivotX和pivotY可以是floot OR percentage
android:pivotX, 表示rotation的中心店坐标,如果是float表示距离图片的左边的x pixels的距离。%表示是在相对于左边x%的距离。%p表示相对于parent container的左边框的距离
android:pivotY表示与TOP的距离
Interpretors
在XML中定义用来改变图片 rate of change in an animation. 让当前的animation accelerated , repeated, bounced等。用android:interpolator形式添加给animation元素。 android中的所有的interpolator都是interpolator的子类。
@android:interpolator=“@android:anim/x_x_x”
其中 anticipate表示先往回缩
overshoot表示先多显示预定的final value再回到final value
accelerate是加速显示
decelerate减速显示
bounce在最后view震动
cycle设定重复显示动画几次
accelerateDecelerateInterpolator开始和结束时减速,中间加速
目前发现针对furfaceview的tween animation不好用,问题发生在onKeyUp里面,虽然所有的代码都能执行,可是屏幕没有效果。