下面放入layout.aly

{
  LinearLayout;
  layout_width="fill";
  layout_height="fill";
  orientation="vertical";
  {
    LinearLayout;
    layout_width="fill";
    id="a";
    layout_height="56dp";
    background="#FF9800";
    {
      TextView;
      layout_gravity="center";
      text="直接运行动画";
    };
  };
  {
    Button;
    id="button1";
    text="从中心扩散动画";
  };
  {
    LinearLayout;
    layout_width="fill";
    id="b";
    layout_height="224dp";
    background="#795548";
  };
  {
    Button;
    id="button2";
    text="从左上扩散动画";
  };
  {
    LinearLayout;
    layout_width="fill";
    id="c";
    layout_height="fill";
    background="#8BC34A";
  };
};

下面放入main.lua

require "import"
import "android.app.*"
import "android.os.*"
import "android.widget.*"
import "android.view.*"
import "layout" --导入布局
--注意本demon只能在安卓5.0+运行
--下面有参数讲解
import "android.view.animation.*"--导入
import "java.lang.Math"--导入
import "android.view.*"--导入
import "com.androlua.Ticker"--导入
activity.setTitle('揭露动画')
activity.setContentView(loadlayout(layout))
--activity.setTheme(android.R.style.Theme_Material_Light)--md主题
--动画部分
--直接运行的动画
t=Ticker()--时间为零的计时器
t.Period=0
t.start()
t.onTick=function()
  t.stop()--停止
  --动画事件
  animator = ViewAnimationUtils.createCircularReveal(a,0,0,0,Math.hypot(a.getWidth(), a.getHeight()));
  animator.setInterpolator(AccelerateInterpolator());
  animator.setDuration(2000);
  animator.start();
end
--中心扩散动画
function button1.onClick()--点击事件
  --动画
  animator = ViewAnimationUtils.createCircularReveal(b,b.getWidth()/2,b.getHeight()/2,0,b.getWidth());
  animator.setInterpolator(AccelerateInterpolator());
  animator.setDuration(2000);
  animator.start();
end
--左上扩散动画
function button2.onClick()--点击事件
  --动画
  animator = ViewAnimationUtils.createCircularReveal(c,0,0,0,Math.hypot(c.getWidth(), c.getHeight()));
  animator.setInterpolator(AccelerateInterpolator());
  animator.setDuration(2000);
  animator.start();
end
--[[参数解释
animator = ViewAnimationUtils.createCircularReveal(id,centerX,centerY,startRadius,startRadius); 
  animator.setInterpolator(AccelerateInterpolator()); 
  animator.setDuration(2000); 
  animator.start();
  
  centerX是动画开始的中心点X
  centerY是动画开始的中心点Y
  第一个startRadius 动画开始半径
  第二个startRadius 动画结束半径
  animator.setDuration(2000)是动画时长
  ]]
最后修改:2020 年 08 月 20 日
如果觉得我的文章对你有用,请随意赞赏