找回密码
 免费注册

QQ登录

只需一步,快速开始

搜索
查看: 2|回复: 0

【教程】远程赋值 进阶版按行读取

[复制链接]

【教程】远程赋值 进阶版按行读取

[复制链接]

幼儿园


UID
144
主题
8
回帖
0
金币
0 枚
银币
26 枚
铜币
30 枚
下载币
53 枚
在线时间
5 小时

QQ

最佳新人活跃会员热心会员

xk***

幼儿园


UID
144
主题
8
回帖
0
金币
0 枚
银币
26 枚
铜币
30 枚
下载币
53 枚
在线时间
5 小时

QQ

最佳新人活跃会员热心会员

昨天 18:21 | 显示全部楼层 |阅读模式 来自 湖南

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?免费注册

×

【教程】远程赋值 进阶版按行读取

【教程】远程赋值    进阶版按行读取


  1. --
  2. -- @author 寒歌
  3. -- @description Main是应用的主模块,其中注册了应用运行中UI事件的回调、Activity生命周期的回调等
  4. -- 你也可以在此编写启动事件代码,或控制应用运行逻辑、自定义应用UI等等。
  5. -- @other 本模版已为你编写好基础事件,建议在阅读注释并理解相关参数意义后再进行扩展编写
  6. --

  7. -- ****默认导入包****
  8. require "import"
  9. import "android.os.*"
  10. import "android.widget.*"
  11. import "android.view.*"
  12. -- ****不需要请删除****

  13. -- 状态栏沉浸透明
  14. import "android.graphics.Color"
  15. local window=this.getWindow()
  16. window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
  17. window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
  18. window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
  19. window.setStatusBarColor(Color.TRANSPARENT)
  20. 状态栏高度=this.getResources().getDimensionPixelSize(luajava.bindClass("com.android.internal.R$dimen")().status_bar_height)
  21. -- 按行取值(过滤空白行)
  22. function 按行取值(内容,行数)
  23.   local s = 0
  24.   for a in 内容:gmatch("(.-)\n") do
  25.     if #a > 0 then
  26.       s = s + 1
  27.       if s == tonumber(行数) then return a end
  28.     end
  29.   end
  30.   local last = 内容:match("([^\n]+)$")
  31.   if last and #last > 0 then
  32.     s = s + 1
  33.     if s == tonumber(行数) then return last end
  34.   end
  35. end
  36. -- 获取远程数据并赋值
  37. url="http://jishiben.site/?s=123123/k5ml4oOg:text"--网页链接
  38. Http.get(url, nil, "UTF-8", nil, function(状态码, 远程内容)
  39.   -- 按行提取
  40.   local 我是标题 = 按行取值(远程内容,1)
  41.   标题.setText(我是标题)
  42.   local 第一行 = 按行取值(远程内容,2)
  43.   第一行文本.setText(第一行)
  44.   local 第二行 = 按行取值(远程内容,3)
  45.   第二行文本.setText(第二行)
  46.   local 第三行 = 按行取值(远程内容,5)
  47.   第三行文本.setText(第三行)
  48.   local 我是图片 = 按行取值(远程内容,4)
  49.   图片.setImageBitmap(loadbitmap(我是图片))
  50.   --没有获取数据时
  51.   local 赞美 = 按行取值(远程内容,6)--不存在的数据第6行
  52.   赞美美女.setText(赞美 or "当内容失败就会显示我,这个美女真好看")
  53.   --[[也可以这样写,省事,但是记忆不好还是重新写变量吧!
  54.   标题.setText(按行取值(远程内容,1))
  55. ]]
  56. end)
  57. -- 文本控件
  58. function 文本(内容,id)
  59.   return {
  60.     TextView;
  61.     id=id;
  62.     text=内容;
  63.     textSize="17.5sp";
  64.     textColor="#222222";
  65.   }
  66. end
  67. -- 标题栏布局
  68. 标题栏布局={
  69.   LinearLayout;
  70.   orientation="horizontal";
  71.   layout_width="fill";
  72.   layout_height="56dp";
  73.   layout_marginTop=状态栏高度;
  74.   gravity="left|center";
  75.   {
  76.     TextView;
  77.     id="标题";
  78.     layout_marginLeft="4%w";
  79.     layout_weight="1";
  80.     textSize="18sp";
  81.     textColor="#ffffff";
  82.     singleLine=true;
  83.   },
  84.   {
  85.     ImageView;
  86.     layout_width="56dp";
  87.     layout_height="56dp";
  88.     padding="16dp";
  89.     src="icon.png";
  90.   },
  91. }
  92. -- 主布局
  93. layout={
  94.   LinearLayout;
  95.   orientation="vertical";
  96.   layout_width="fill";
  97.   layout_height="fill";
  98.   {
  99.     LinearLayout;
  100.     orientation="vertical";
  101.     layout_width="fill";
  102.     layout_height="wrap";
  103.     background="#ff2196f3";
  104.     elevation="4dp";
  105.     标题栏布局,
  106.   };
  107.   {
  108.     ScrollView;
  109.     layout_width="fill";
  110.     layout_height="fill";
  111.     overScrollMode=View.OVER_SCROLL_NEVER;
  112.     verticalScrollBarEnabled=false;
  113.     {
  114.       LinearLayout;
  115.       orientation="vertical";
  116.       layout_width="fill";
  117.       layout_height="fill";
  118.       --开始布局
  119.       --文本
  120.       文本(nil,"第一行文本"),
  121.       文本(nil,"第二行文本"),
  122.       文本(nil,"第三行文本"),
  123.       --图片
  124.       {
  125.         ImageView;
  126.         id="图片";
  127.         layout_width="wrap";
  128.         layout_height="wrap";
  129.       },
  130.       文本(nil,"赞美美女"),
  131.     };
  132.   };
  133. }
  134. activity.setContentView(loadlayout(layout))--全屏布局
复制代码


楼主热帖
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

Archiver|小黑屋|FusionApp论坛 | |网站地图|网站地图
ANK V1.1.8 正式版支持 | 本站服务器位于中国香港,无需办理内地 ICP 备案,运营遵守香港地区相关法律规定。

GMT+8, 2026-8-7 03:45

快速回复