123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- -- 设置为竖屏模式
- activity.setRequestedOrientation(1)
- function hexToColor(hex)
- -- 去掉 # 前缀
- hex = hex:gsub("#", "")
- -- 将十六进制转换为数字
- local color = tonumber(hex, 16)
- return color
- end
- local hexColor = "#ff009688"
- local MyColor = hexToColor(hexColor)
- 写入文件(随机色,MyColor)
- 读取颜色(随机色,随机色)
- layout = {
- LinearLayout,
- orientation ='vertical',
- layout_width = 'fill',
- layout_height = 'fill',
- background = '#ffffff',
- {
- TextView,
- text = '休闲游戏',
- textSize = '20sp',
- textColor = '#333333',
- layout_gravity = "center|bottom",
- layout_marginTop = '35px',
- },
- {
- TextView,
- layout_width = '97.4%w',
- layout_height = '5px',
- layout_marginTop = '10dp',
- layout_marginBottom = '10dp',
- layout_gravity = 'center',
- backgroundColor = MyColor
- },
- {
- GridView,
- id = "list",
- numColumns = 3,
- layout_width = 'fill',
- layout_height = 'fill',
- horizontalSpacing = "3dp",
- verticalSpacing = "0dp",
- layout_gravity = "center",
- OverScrollMode = 2
- }
- }
- webView.addView(loadlayout(layout))
- function 布局边框(边框粗细, 边框颜色, 背景颜色, 圆角大小)
- import "android.graphics.drawable.GradientDrawable"
- drawable = GradientDrawable()
- drawable.setShape(GradientDrawable.RECTANGLE)
- drawable.setStroke(边框粗细, tonumber(边框颜色))
- drawable.setColor(tonumber(背景颜色))
- drawable.setCornerRadius(圆角大小)
- return drawable
- end
- item = {
- LinearLayout,
- layout_height = "48dp",
- layout_width = "fill",
- {
- LinearLayout,
- layout_height = "fill",
- layout_width = "fill",
- layout_margin = "5dp",
- BackgroundDrawable = 布局边框(4,MyColor, 0x00000000, 15),
- {
- TextView,
- id = "name",
- layout_height = "fill",
- layout_width = "fill",
- gravity = "center",
- textColor = "#FF000000"
- },
- {
- TextView,
- id = "tools",
- layout_width = "0dp",
- layout_height = "0dp"
- }
- }
- }
- adapter = LuaAdapter(activity, item)
- function getToolsText(v)
- return v.Tag.tools and v.Tag.tools.text or ""
- end
- list.onItemClick = function(l, v, p, i)
- local toolsText = getToolsText(v)
- 子页面('安卓',toolsText)
- end
- list.onItemLongClick = function(l, v, p, i)
- local toolsText = getToolsText(v)
- --写入文件(自动旋转,"已开启自动旋转")
- --写入文件(全屏,"已开启全屏")
- if v.Tag.name.text:find '猜数字' then
- 子页面('安卓','file:///android_asset/htm/caishuzi/index.html')
- elseif v.Tag.name.text:find '贪吃蛇' then
- 子页面('安卓','file:///android_asset/htm/she/index.html')
- elseif v.Tag.name.text:find '方块' then
- 子页面('安卓','file:///android_asset/htm/eluosi/index.html')
- elseif v.Tag.name.text:find '五子棋' then
- 子页面('安卓','file:///android_asset/htm/wzq/index.html')
- elseif v.Tag.name.text:find '魔方' then
- 子页面('安卓','file:///android_asset/htm/mofang/index.html')
- return true
- end
- end
- list.Adapter = adapter
- local dataList = {
- {name = "经典猜数字", tools = "http://mov.txcgb.site/dh/game/caishuzi/"},
- {name = "经典贪吃蛇", tools = "http://mov.txcgb.site/dh/game/she/"},
- {name = "俄罗斯方块", tools = "http://mov.txcgb.site/dh/game/eluosi/"},
- {name = "五子棋", tools = "http://mov.txcgb.site/dh/game/wzq/"},
- {name = "3D魔方", tools = "http://mov.txcgb.site/dh/game/mofang/"},
- }
- for _, data in ipairs(dataList) do
- adapter.add(data)
- end
|