Animation RotateAnimation详解

fromDegress为0,则从view本来的位置绕着旋转点,旋转toDegress度,若fromDegress为90,

toDegress为180,则view瞬间跳转到以旋转90度的位置,然后再顺时针旋转90度。

?

1.RotateAnimation(float fromDegrees, float toDegrees)

默认的旋转点为view的左上角

X轴顺时针转动到fromDegrees为旋转的起始点,
X轴顺时针转动到toDegrees为旋转的起始点。
 如fromDegrees=0,toDegrees=90;为左上角顶点为旋转点。0度为起始点,90度为终点。进行旋转,旋转了90度
 如fromDegrees=60,toDegrees=90;为左上角顶点为旋转点。60度为起始点,90度为终点。进行旋转,旋转了90-60=30度


2.RotateAnimation(float fromDegrees, float toDegrees, float pivotX, float pivotY)

(pivotX,pivotY)为旋转点。pivotX为距离左侧的偏移量,pivotY为距离顶部的偏移量。即为相对于View左上角(0,0)的坐标点,而不是相对于整个屏幕的左上角。
如View?width=100px,height=100px
RotateAnimation(0,10,100,100);则以右下角顶点为旋转点,从原始位置顺时针旋转10度
RotateAnimation(0,90,50,50);则以View的中心点为旋转点,旋转90度

3.RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue,

int pivotYType, float pivotYValue)

 pivotXType,?pivotXValue,?pivotYType,?pivotYValue??旋转点类型及其值。
Animation.ABSOLUTE为绝对值?其他为百分比。这个和平移动画的一样,不了解可以去那看
如RotateAnimation(0,?90,?Animation.RELATIVE_TO_SELF,?0.5f,?

Animation.RELATIVE_TO_SELF,?0.5f);?按中心点旋转90度
效果和2例中的RotateAnimation(0,90,50,50);则以View的中心点为旋转点,旋转90度?。效果一样

RotateAnimation rotate = new RotateAnimation(0, 360,
	Animation.RELATIVE_TO_SELF, 0.5f, 
	Animation.RELATIVE_TO_SELF, 0.5f);
				
RotateAnimation rotate = new RotateAnimation(0, 360,
	Animation.RELATIVE_TO_PARENT, 0.5f, 
	Animation.RELATIVE_TO_PARENT, 0.5f);

?上面的rotate是相对于view自身来说的,所以旋转点事view的中心,下面的是相对于Parent来说的,但是起始点是view的左上角,也就是说并不是在整个parent的中心,而是在view的左上角到parent的右边界的中线和view的左上角到parent的下边界的中线的交点。

?

new?RotateAnimation(0,?180,?centerX,centerY);

第一个参数表示动画的起始角度,第二个参数表示动画的结束角度,第三个表示动画的旋转中心x轴,第四个表示动画旋转中心y轴。

rotateAnimation.setDuration(1000?*?20);

表动画持续20s。

rotateAnimation.setFillAfter(true);

 ture表示动画结束后停留在动画的最后位置,false表示动画结束后回到初始位置,默认为false。


setFillBefore(boolean fillBefore)

 true标示动画执行后,空间将回到动画执行之前的状态


mView.startAnimation(rotateAnimation);

表示在mView中启动动画。 

setStartOffSet(long startOffSet)

设置动画执行之前的时间

setRepeatCount(int repeatCount)

 设置动画重复执行的次数

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值