一、animation
RotateAnimation, ScaleAnimation, TranslateAnimation
1、RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
参数说明:角度从多少度到多少度,注意是旋转角度;
旋转的中心的确定,是相对于控件的左上角那个点的座标 加上系数
如:
RotateAnimation rotateAnimation = new RotateAnimation(
90, 360,//从旋转了90度后开始,开始转到360
Animation.RELATIVE_TO_PARENT, 2f,//相对于自己左上角座标,加上自己1倍宽
Animation.RELATIVE_TO_PARENT, 0f //相对于自己左上角座标,加上自己0倍宽
)
2、ScaleAnimation(float fromX, float toX, float fromY, float toY, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
ScaleAnimation scaleAnimation = new ScaleAnimation(
1, 0.1f, //x缩放的系数(倍数,从多少倍放到多少倍)
1, 0.1f, //y缩放的系数(倍数,从多少倍放到多少倍)
Animation.RELATIVE_TO_PARENT, 0.5f,//相对于父控件左上角座标,加上父控件的0.5倍宽
Animation.RELATIVE_TO_SELF, 0.5f); //相对于自己左上角座标,加上自己0.5倍宽
![](http://hi.csdn.net/attachment/201105/8/0_1304865671j67j.gif)
3、TranslateAnimation移动动画
TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)
全遵循相对控件的左上角坐标 加上系数倍数后的坐标
TranslateAnimation translateAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0f,
Animation.RELATIVE_TO_SELF, 1.0f
)
4.添加动画开始和完成的事件
TranslateAnimation tmpAnimation = new TranslateAnimation(midLinearlayout.getLeft(),midLinearlayout.getLeft(),midLinearlayout.getTop(),midLinearlayout.getTop()+100);
//tmpAnimation.setFillAfter(true);
tmpAnimation.setDuration(2000);
tmpAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
//To change body of implemented methods use File | Settings | File Templates.
}
});