suiji.txt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. --随机数
  2. layout={
  3. LinearLayout,
  4. orientation="vertical",
  5. layout_width="fill",
  6. {
  7. LinearLayout,
  8. layout_width="fill",
  9. padding="16dp",
  10. paddingTop="8dp",
  11. paddingBottom="8dp",
  12. gravity="center",
  13. {
  14. EditText,
  15. gravity="center",
  16. ems=6,
  17. singleLine=true,
  18. layout_marginTop='30dp';--布局顶距
  19. backgroundColor=0,
  20. hint="最小值",
  21. inputType="number",
  22. id="min",
  23. text="0",
  24. layout_weight=1,
  25. },
  26. {
  27. TextView,
  28. layout_gravity="center",
  29. layout_marginTop='30dp';--布局顶距
  30. text="<",
  31. },
  32. {
  33. EditText,
  34. ems=6,
  35. gravity="center",
  36. layout_marginTop='30dp';--布局顶距
  37. backgroundColor=0,
  38. hint="最大值",
  39. text="35",
  40. inputType="number",
  41. layout_weight=1,
  42. id="max",
  43. singleLine=true,
  44. },
  45. },
  46. {
  47. ScrollView,
  48. layout_width="fill",
  49. layout_weight=1,
  50. {
  51. TextView,
  52. id="tex",
  53. textSize="56dp",
  54. layout_gravity="center",
  55. layout_height="fill",
  56. padding="16dp",
  57. textIsSelectable=true,
  58. },
  59. },
  60. {
  61. Button,
  62. text="生成",
  63. layout_width="fill",
  64. layout_marginBottom='450dp';--布局底距
  65. layout_margin="16dp",
  66. textColor=0xfffafafa,
  67. id="bt",
  68. textSize="16dp",
  69. },
  70. };
  71. require "import"
  72. import "android.app.*"
  73. import "android.os.*"
  74. import "android.widget.*"
  75. import "android.view.*"
  76. activity.setTheme(android.R.style.Theme_DeviceDefault_Light)--设置md主题
  77. --activity.setTheme(R.AndLua1)
  78. activity.setTitle("随机数生成")--标题
  79. activity.setContentView(loadlayout(layout))
  80. --控件圆角函数
  81. function 控件圆角(id,InsideColor,radiu)
  82. import "android.graphics.drawable.GradientDrawable"
  83. drawable = GradientDrawable()
  84. drawable.setShape(GradientDrawable.RECTANGLE)
  85. drawable.setColor(InsideColor) drawable.setCornerRadii({radiu,radiu,radiu,radiu,radiu,radiu,radiu,radiu});
  86. id.setBackgroundDrawable(drawable)
  87. end
  88. 控件圆角(bt,0xFF2196F3,360)--设置按钮圆角
  89. --来着快乐程序,代码手册首次整理https://www.lanzous.com/i82ncaf
  90. tex.setText(tostring(math.random(0,35)))--设置默认数值为1-35@的随机数值
  91. bt.onClick=function()--按钮点击事件
  92. tex.setText(tostring(math.random(tonumber(min.text),tonumber(max.text))))--获取输入框的数值并转换为number,取随机数后转换为string型数值并设置给tex
  93. end