game.txt 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. -- 设置为竖屏模式
  2. activity.setRequestedOrientation(1)
  3. function hexToColor(hex)
  4. -- 去掉 # 前缀
  5. hex = hex:gsub("#", "")
  6. -- 将十六进制转换为数字
  7. local color = tonumber(hex, 16)
  8. return color
  9. end
  10. local hexColor = "#ff009688"
  11. local MyColor = hexToColor(hexColor)
  12. 写入文件(随机色,MyColor)
  13. 读取颜色(随机色,随机色)
  14. layout = {
  15. LinearLayout,
  16. orientation ='vertical',
  17. layout_width = 'fill',
  18. layout_height = 'fill',
  19. background = '#ffffff',
  20. {
  21. TextView,
  22. text = '休闲游戏',
  23. textSize = '20sp',
  24. textColor = '#333333',
  25. layout_gravity = "center|bottom",
  26. layout_marginTop = '35px',
  27. },
  28. {
  29. TextView,
  30. layout_width = '97.4%w',
  31. layout_height = '5px',
  32. layout_marginTop = '10dp',
  33. layout_marginBottom = '10dp',
  34. layout_gravity = 'center',
  35. backgroundColor = MyColor
  36. },
  37. {
  38. GridView,
  39. id = "list",
  40. numColumns = 3,
  41. layout_width = 'fill',
  42. layout_height = 'fill',
  43. horizontalSpacing = "3dp",
  44. verticalSpacing = "0dp",
  45. layout_gravity = "center",
  46. OverScrollMode = 2
  47. }
  48. }
  49. webView.addView(loadlayout(layout))
  50. function 布局边框(边框粗细, 边框颜色, 背景颜色, 圆角大小)
  51. import "android.graphics.drawable.GradientDrawable"
  52. drawable = GradientDrawable()
  53. drawable.setShape(GradientDrawable.RECTANGLE)
  54. drawable.setStroke(边框粗细, tonumber(边框颜色))
  55. drawable.setColor(tonumber(背景颜色))
  56. drawable.setCornerRadius(圆角大小)
  57. return drawable
  58. end
  59. item = {
  60. LinearLayout,
  61. layout_height = "48dp",
  62. layout_width = "fill",
  63. {
  64. LinearLayout,
  65. layout_height = "fill",
  66. layout_width = "fill",
  67. layout_margin = "5dp",
  68. BackgroundDrawable = 布局边框(4,MyColor, 0x00000000, 15),
  69. {
  70. TextView,
  71. id = "name",
  72. layout_height = "fill",
  73. layout_width = "fill",
  74. gravity = "center",
  75. textColor = "#FF000000"
  76. },
  77. {
  78. TextView,
  79. id = "tools",
  80. layout_width = "0dp",
  81. layout_height = "0dp"
  82. }
  83. }
  84. }
  85. adapter = LuaAdapter(activity, item)
  86. function getToolsText(v)
  87. return v.Tag.tools and v.Tag.tools.text or ""
  88. end
  89. list.onItemClick = function(l, v, p, i)
  90. local toolsText = getToolsText(v)
  91. 子页面('安卓',toolsText)
  92. end
  93. list.onItemLongClick = function(l, v, p, i)
  94. local toolsText = getToolsText(v)
  95. --写入文件(自动旋转,"已开启自动旋转")
  96. --写入文件(全屏,"已开启全屏")
  97. if v.Tag.name.text:find '猜数字' then
  98. 子页面('安卓','file:///android_asset/htm/caishuzi/index.html')
  99. elseif v.Tag.name.text:find '贪吃蛇' then
  100. 子页面('安卓','file:///android_asset/htm/she/index.html')
  101. elseif v.Tag.name.text:find '方块' then
  102. 子页面('安卓','file:///android_asset/htm/eluosi/index.html')
  103. elseif v.Tag.name.text:find '五子棋' then
  104. 子页面('安卓','file:///android_asset/htm/wzq/index.html')
  105. elseif v.Tag.name.text:find '魔方' then
  106. 子页面('安卓','file:///android_asset/htm/mofang/index.html')
  107. return true
  108. end
  109. end
  110. list.Adapter = adapter
  111. local dataList = {
  112. {name = "经典猜数字", tools = "http://mov.txcgb.site/dh/game/caishuzi/"},
  113. {name = "经典贪吃蛇", tools = "http://mov.txcgb.site/dh/game/she/"},
  114. {name = "俄罗斯方块", tools = "http://mov.txcgb.site/dh/game/eluosi/"},
  115. {name = "五子棋", tools = "http://mov.txcgb.site/dh/game/wzq/"},
  116. {name = "3D魔方", tools = "http://mov.txcgb.site/dh/game/mofang/"},
  117. }
  118. for _, data in ipairs(dataList) do
  119. adapter.add(data)
  120. end