一种控制对象位置的动画。
构造方法
TranslateAnimation (fromXDelta, toXDelta, fromYDelta, toYDelta)
Parameters | |
---|---|
fromXDelta |
在动画开始时应用X坐标的变化 |
toXDelta |
在动画结束时应用X坐标的变化 |
fromYDelta |
在动画开始时应用的Y坐标变化 |
toYDelta |
在动画结束时应用的Y坐标变化 |
TranslateAnimation ( fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, toYType, toYValue)
Parameters | |
---|---|
fromXType |
指定应该如何解释fromXValue。可选值 Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_PARENT. |
fromXValue |
在动画开始时应用X坐标的变化。如果fromXType是绝对的,这个值可以是绝对数字;如果是绝对的,这个值可以是百分比(1.0是100%)。 |
toXType |
指定应如何解释toXValue。可选值 Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_PARENT. |
toXValue |
在动画结束时应用X坐标的变化。如果toXType是绝对的,这个值可以是绝对数值,如果是100%,这个值可以是百分比(1.0是100%)。 |
fromYType |
指定fromYValue应该如何解释。可选值 Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_PARENT. |
fromYValue |
在动画开始时应用的Y坐标变化。如果fromYType是绝对的,这个值可以是绝对数字,否则可以是百分比(1.0是100%)。 |
toYType |
指定应该如何解释toYValue,可选值 Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_PARENT. |
toYValue |
在动画结束时应用的Y坐标变化。如果toYType是绝对的,这个值可以是绝对数字;如果是绝对的,这个值可以是百分比(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 = TranslateAnimation(0, 100, 0, 100)
-- 设置动画时间
animate.setDuration(3000)
-- 点击按钮开始动画
button.onClick = function()
button.startAnimation(animate)
end
end
function main()
initAnimate()
end
效果: