发帖
充值
 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
首页源码分享懒人精灵_动态UI示例_显示图片

懒人精灵_动态UI示例_显示图片

9
回复
4215
查看
[ 复制链接 ]
已绑定手机

46

主题

118

回帖

2831

积分

版主

积分
2831
2021-11-11 14:45:30 显示全部楼层 阅读模式


  1. function PicPath(uipath)
  2.     -- 遍历路径获取图片信息
  3.     local p = exec(string.format("ls %s",uipath))
  4.     if p ~= nil then
  5.         
  6.         io.output("/mnt/sdcard/test.txt")
  7.         io.write(tostring(p))
  8.         io.close()
  9.         
  10.     end
  11.    
  12.    
  13. end

  14. function GetPicpath(path)
  15.     -- 打开创建filepath.txt文件 写入 test.txt文件的内容 并返回字符串数据
  16.     local pathtable = {}
  17.    
  18.     io.output("/mnt/sdcard/filepath.txt")            -- 创建filepath 保存拼接好的路径
  19.     for line in io.lines("/mnt/sdcard/test.txt") do    -- 打开test文件 遍历文件名 进行拼接
  20.         str = path.."/"..line
  21.         io.write(tostring(str..'\n'))
  22.         
  23.         table.insert(pathtable,str)
  24.     end
  25.    
  26.     io.input("/mnt/sdcard/filepath.txt")            -- 打开filepath.txt文件读取路径字符串 并返回
  27.    
  28.     ReadContent = io.read("*a")
  29.     io.close()
  30.    
  31.     return pathtable
  32.    
  33. end


  34. function GetUIPath()
  35.     -- 填写图片文件夹路径
  36.     ui.newRow("layout1","row100")
  37.     ui.addTextView("layout1","tvId100","指定图片目录路径:")
  38.     ui.addEditText("layout1","editId100","/mnt/sdcard/Pictures")
  39.     ui.addButton("layout1","btnnId100","显示\n图片",150,150)
  40.     ui.setGravity("editId100",48)
  41.     ui.setGravity("tvId100",48)
  42.     ui.setGravity("btnnId100",48)
  43.    
  44.    
  45.    
  46.     return ui.getText("editId100")
  47. end

  48. function GetPicName(tab)
  49.     -- 获取图片文件名 如果是以jpg png bmp 后缀名结尾的图片添加到PicFilePath表里面
  50.     local PicFilePath = {}
  51.     for k,v in pairs(tab) do
  52.         if string.find(v, ".jpg", 1) or string.find(v, ".png", 1) or string.find(v, ".bmp", 1)then
  53.             
  54.             table.insert(PicFilePath,v)
  55.         end
  56.         
  57.     end
  58.     return PicFilePath
  59. end



  60. function NewRow(tab)
  61.     -- 根据 PicFilePath 表里面的图片创建对应的 动态ui控件
  62.     ui.newRow("layout1","row0",-1,-1)
  63.     btTab = {}
  64.     for k,v in pairs(tab) do
  65.         
  66.         ui.newRow("layout1",string.format("row%s",k),-2,-2)
  67.         ui.addImageView("layout1",string.format("imgId%s",k),v,400,400)
  68.         -- ui.addButton("layout1",string.format("btnnId%s",k),v)
  69.         ui.addEditText("layout1",string.format("btnnId%s",k),v)
  70.         ui.setGravity(string.format("imgId%s",k),3)
  71.         
  72.     end
  73.    
  74. end


  75. function onClick()
  76.     -- 点击图片显示
  77.     if fileExist(PicFilePath[1]) then
  78.         NewRow(PicFilePath)
  79.     end
  80. end


  81. function UIViewPic()
  82. -- 点击显示图片 显示目录下的图片和路径
  83.     ui.newLayout("layout1",-1)
  84.     ui.setTitleText("layout1","显示图片")
  85.     local PathStr = GetUIPath()
  86.     PicPath(PathStr)
  87.     -- print(GetPicpath(PathStr))
  88.     PicFilePath = GetPicName(GetPicpath(PathStr))
  89.     ui.setOnClick("btnnId100","onClick()")
  90.    
  91.    
  92. end



  93. function run()
  94.     -- 执行函数
  95.     UIViewPic()
  96.     ui.show("layout1",false)
  97.     sleep(100000)
  98. end

  99. run()
复制代码
运行结果图片:
1.png

使用道具
举报

0

主题

39

回帖

65

积分

注册会员

积分
65
还不错
回复
使用道具
举报

1

主题

24

回帖

70

积分

注册会员

积分
70
还不错
回复
使用道具
举报

2

主题

25

回帖

304

积分

中级会员

积分
304

还不错
回复
使用道具
举报

2

主题

34

回帖

128

积分

注册会员

积分
128
QQ
勇敢的牛牛不怕困难
回复
使用道具
举报

2

主题

19

回帖

95

积分

注册会员

积分
95
支持一下,希望楼主做的更好,加油!



                                            藏起来的小尾巴,不让你看!  
    回复
    使用道具
    举报

    0

    主题

    34

    回帖

    58

    积分

    注册会员

    积分
    58
    动态UI还是很好的
    回复
    使用道具
    举报
    已绑定手机

    0

    主题

    28

    回帖

    199

    积分

    注册会员

    积分
    199
    来捧场了····
    回复
    使用道具
    举报
    已绑定手机

    3

    主题

    40

    回帖

    3454

    积分

    论坛元老

    积分
    3454
    回复
    使用道具
    举报

    0

    主题

    13

    回帖

    55

    积分

    注册会员

    积分
    55
    太厉害,要学习的东西太多了
    回复
    使用道具
    举报
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则