一种控制对象alpha级别的动画。对于淡入淡出很有用。

构造方法

AlphaAnimation(fromAlpha,toAlpha)

Parameters
fromAlpha 启动动画的alpha值,其中1.0表示完全不透明,0.0表示完全透明。
toAlpha 动画的结束alpha值。

使用示例:

  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 = AlphaAnimation(1, 0)
  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