一种控制对象旋转的动画。这个旋转发生在平面上。您可以指定用于旋转中心的点,其中(0,0)是左上角的点。如果未指定,(0,0)是默认旋转点。

构造方法

RotateAnimation (fromDegrees,toDegrees)

Parameters
fromDegrees 在动画开始时应用的旋转偏移。
toDegrees 旋转偏移应用于动画的结尾。

RotateAnimation (fromDegrees, toDegrees, pivotX, pivotY)

Parameters
fromDegrees 在动画开始时应用的旋转偏移。
toDegrees 旋转偏移应用于动画的结尾。
pivotX 围绕旋转对象的点的X坐标,指定为绝对值,其中0是左边缘。
pivotY 关于旋转对象的点的Y坐标,指定为一个绝对数,其中0是上边缘。

RotateAnimation (fromDegrees, toDegrees, pivotXType, pivotXValue, pivotYType, pivotYValue)

Parameters
fromDegrees 在动画开始时应用的旋转偏移。
toDegrees 旋转偏移应用于动画的结尾。
pivotXType 指定pivotXValue应该如何解释。可选值
Animation.ABSOLUTE,
Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_PARENT.
pivotXValue 围绕旋转对象的点的X坐标,指定为绝对值,其中0是左边缘。如果pivotXType是绝对的,这个值可以是绝对数字,否则可以是百分比(1.0是100%)。
pivotYType 指定pivotYValue应该如何解释。可选值
Animation.ABSOLUTE,
Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_PARENT.
pivotYValue 关于旋转对象的点的Y坐标,指定为一个绝对数,其中0是上边缘。如果pivotYType是绝对的,那么这个值可以是绝对数字,否则可以是百分比(1.0是100%)。

使用示例:

  1. require "import"
  2. import "android.os.*"
  3. import "android.app.*"
  4. import "android.view.*"
  5. import "android.widget.*"
  6. import "android.view.animation.*"
  7. local layout = loadlayout({
  8. LinearLayout,
  9. layout_width = "fill",
  10. layout_height = "fill",
  11. gravity = "center",
  12. {
  13. Button,
  14. layout_width = "100dp",
  15. layout_height = "50dp",
  16. text = "开始动画",
  17. id = "button",
  18. },
  19. })
  20. activity.setContentView(layout)
  21. function initAnimate()
  22. -- 定义旋转动画,用的第一个构造方法,只定义了旋转角度
  23. local animate = RotateAnimation(0, 90)
  24. -- 设置动画时间3
  25. animate.setDuration(3000)
  26. -- 点击按钮开始动画
  27. button.onClick = function()
  28. button.startAnimation(animate)
  29. end
  30. end
  31. function main()
  32. initAnimate()
  33. end

效果:

补间动画-旋转动画 - 图1