使用懒人精灵IDE编写一个基于动态UI的数字抽奖示例.
数字抽奖.lua 文件源码
- function 添加数字(数值)
- local 数字表 = {}
-
- for i=1,math.tointeger(数值) do
- table.insert(数字表,i)
- end
- return 数字表
- end
- function 随机抽奖(总表)
- ui.setTextView("tvId3",">>>>>> 正在抽奖 <<<<<<")
- ui.setTextSize("tvId4",30)
- for i=1,30 do
- ui.setTextView("tvId4",string.format("%d",rnd(1,#总表)))
- sleep(200)
- end
- ui.setTextView("tvId3",">>>>>> 中奖号码 <<<<<<")
- ui.setTextColor("tvId4","#ffff0000")
- ui.setTextSize("tvId4",50)
- ui.setTextView("tvId4",string.format("%d",rnd(1,#总表)))
-
- end
- function onClick()
- print('控件点击属性')
- local tabArr = ui.getData()
- print(tabArr)
- local 总数 = ui.getValue("editId1")
- if tabArr.btnnId1 == '开始抽奖'then
- local 数字总表 = 添加数字(总数)
- 随机抽奖(数字总表)
- end
- end
- -- 创建一个布局,这文本框,输入框,按钮信息
- ui.newLayout("layout1",-1,-1)
- ui.setTitleText("layout1","抽奖系统")
- ui.addTextView("layout1","tvId1","请输入总人数")
- ui.addEditText("layout1","editId1","")
- ui.addButton("layout1","btnnId1","开始抽奖")
- ui.newRow("layout1","row1",-2,-2)
- ui.addTextView("layout1","tvId3",">>>>>> 准备抽奖 <<<<<<")
- ui.setTextSize("tvId3",30)
- ui.setTextColor("tvId3","#ffff0000")
- ui.setGravity("row1",17)
- ui.newRow("layout1","row2",-2,-2)
- ui.addTextView("layout1","tvId4","")
- ui.setGravity("row2",17)
- ui.setPadding("tvId4",10,50,10,10)
- -- 点击按钮执行 随机抽奖函数
- ui.setOnClick("btnnId1","onClick()")
- ui.show("layout1",false)
- sleep(1000000)
复制代码
运行结果图片:
|