一种控制对象旋转的动画。这个旋转发生在平面上。您可以指定用于旋转中心的点,其中(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%)。 |
使用示例:
require "import"
import "android.os.*"
import "android.app.*"
import "android.view.*"
import "android.widget.*"
import "android.view.animation.*"
local layout = loadlayout({
LinearLayout,
layout_width = "fill",
layout_height = "fill",
gravity = "center",
{
Button,
layout_width = "100dp",
layout_height = "50dp",
text = "开始动画",
id = "button",
},
})
activity.setContentView(layout)
function initAnimate()
-- 定义旋转动画,用的第一个构造方法,只定义了旋转角度
local animate = RotateAnimation(0, 90)
-- 设置动画时间3秒
animate.setDuration(3000)
-- 点击按钮开始动画
button.onClick = function()
button.startAnimation(animate)
end
end
function main()
initAnimate()
end
效果: