AndroLua布局分享,简单爬虫,爬取天气信息及图片文字

什么是AndroLua

布局图片.jpg

activity.overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out)
wux={
  LinearLayout;
  layout_height="100%h";
  layout_width="100%w";
  orientation="vertical";
  background="#ffeeefef";
  {
    LinearLayout;
    layout_height="45%h";
    layout_width="100%w";
    orientation="vertical";
    {
      FrameLayout;
      id="menus";
      layout_height="fill";
      layout_width="fill";
      {
        ImageView;
        layout_width="fill";
        src="http://image.wufazhuce.com/FlUgT0jeM_5iPcgS_TiWsOMdW2cx";
        id="mn";
        layout_height="fill";
        scaleType="fitXY";
      };
      {
        TextView;
        layout_gravity="center";
        layout_width="wrap_content";
        gravity="center";
        textSize="90dp";
        layout_height="wrap_content";
        text=os.date("%d");
        textColor="#cfffffff";
      };
      {
        FrameLayout;
        layout_marginTop="24sp";
        layout_width="fill";
        id="gft";
        layout_height="fill";
        background="#00e71e62";
        {
          LinearLayout;
          layout_width="fill";
          gravity="center";
          id="reo";
          layout_height="56dp";
          orientation="horizontal";
          {
            LinearLayout;
            layout_height="fill";
            gravity="center";
            {
              CardView;
              UseCompatPadding=false;
              layout_width="80dp";
              CardElevation="0dp";
              id="wk";
              layout_height="80dp";
              PreventCornerOverlap=false;
              layout_marginLeft="-15dp";
              {
                ImageView;
                layout_margin="-10dp";
                layout_width="fill";
                -- src="tp/navnav.png";
                id="btna";
                layout_height="fill";
                background="#00000000";
                padding="38dp";
              };
            };
          };
          {
            TextView;
            layout_marginLeft="-15dp";
            layout_width="fill";
            singleLine=true;
            gravity="center|left";
            layout_height="fill";
            layout_weight="1";
            textColor="#FFFFFF";
          };
          {
            CardView;
            UseCompatPadding=false;
            Visibility=8;
            layout_width="65dp";
            CardElevation="0dp";
            id="bity1";
            layout_height="65dp";
            PreventCornerOverlap=false;
            layout_marginRight="-17dp";
            {
              ImageView;
              layout_margin="-10dp";
              layout_width="fill";
              --   src="tp/ic_package_variant.png";
              id="btn1";
              layout_height="fill";
              background="#00000000";
              padding="28dp";
            };
          };
          {
            CardView;
            UseCompatPadding=false;
            PreventCornerOverlap=false;
            layout_width="65dp";
            CardElevation="0dp";
            id="bity2";
            layout_height="65dp";
            layout_marginRight="-19dp";
            Visibility=8;
            {
              ImageView;
              layout_margin="-10dp";
              layout_width="fill";
              --  src="tp/ic_right.png";
              id="btn2";
              layout_height="fill";
              background="#00000000";
              padding="28dp";
            };
          };
          {
            CardView;
            UseCompatPadding=false;
            layout_width="65dp";
            CardElevation="0dp";
            id="cdd";
            layout_height="65dp";
            PreventCornerOverlap=false;
            layout_marginRight="-10dp";
            {
              TextView;
              layout_marginTop="10dp";
              layout_width="fill";
              id="fg";
              layout_height="0dp";
              layout_marginLeft="-145dp";
            };
            {
              ImageView;
              layout_margin="-10dp";
              layout_width="fill";
              src="drawable/a.png";
              id="btn3";
              layout_height="fill";
              background="#00000000";
              padding="31dp";
            };
          };
        };
      };
      {
        TextView;
        id="bhj";
        layout_height="24sp";
        background="#00000000";
        layout_width="fill";
      };
    };
  };
  {
    LinearLayout;
    background="#ff2c2e43";
    layout_height="55%h";
    layout_width="100%w";
    orientation="vertical";
    {
      LinearLayout;
      backgroundColor="#ffeeefef";
      layout_height="fill";
      layout_width="fill";
      orientation="vertical";
      {
        LinearLayout;
        layout_gravity="center";
        layout_width="fill";
        gravity="center";
        id="天气部分";
        layout_height="15%h";
        background="img/tp.png";
        orientation="vertical";
        {
          LinearLayout;
          layout_gravity="center";
          layout_width="wrap";
          gravity="center";
          layout_height="wrap";
          orientation="horizontal";
          {
            LinearLayout;
            layout_gravity="center";
            layout_width="20%w";
            gravity="center";
            id="时间部分";
            layout_height="fill";
            layout_marginRight="13.5%w";
            orientation="vertical";
            {
              TextView;
              layout_height="wrap";
              layout_gravity="center";
              layout_width="wrap";
              gravity="center";
              id="asp";
              textSize="20sp";
              text="22:35";
              textColor="#ff000000";
            };
            {
              LinearLayout;
              layout_gravity="center";
              layout_width="wrap";
              gravity="center";
              layout_height="wrap";
              orientation="horizontal";
              {
                TextView;
                layout_gravity="center";
                layout_width="wrap";
                gravity="center";
                id="asp3";
                textSize="12sp";
                text="时段";
                layout_height="wrap";
              };
              {
                TextView;
                layout_marginTop="0dp";
                layout_gravity="center";
                visibility=8;
                textSize="12sp";
                layout_width="6%w";
                gravity="center";
                id="asp2";
                layout_height="wrap";
                text="00";
              };
            };
          };
          {
            LinearLayout;
            gravity="center|right";
            layout_gravity="center|right";
            {
              ImageView;
              layout_gravity="center";
              layout_width="45dp";
              scaleType="fitXY";
              layout_height="45dp";
              id="天气icon";
            };
          };
          {
            LinearLayout;
            layout_gravity="center|right";
            layout_width="wrap";
            gravity="center|right";
            layout_height="wrap";
            layout_marginLeft="3%w";
            orientation="vertical";
            {
              LinearLayout;
              layout_gravity="center";
              gravity="center";
              layout_marginLeft="0dp";
              orientation="vertical";
              {
                LinearLayout;
                layout_gravity="center";
                gravity="center";
                orientation="horizontal";
                {
                  TextView;
                  layout_gravity="center";
                  singleLine=true;
                  gravity="center";
                  id="温度text";
                  textSize="23sp";
                  text="-- ℃";
                  textColor="#ff000000";
                };
              };
              {
                TextView;
                layout_marginTop="0dp";
                layout_gravity="center";
                gravity="center";
                id="温度数据text";
                textSize="12sp";
                singleLine=true;
                text="未知数据";
              };
            };
          };
        };
        {
          LinearLayout;
          layout_marginTop="2%h";
          layout_gravity="center";
          layout_width="fill";
          gravity="center";
          id="其他天气数据";
          layout_height="wrap";
          orientation="horizontal";
          {
            TextView;
            id="当前城市text";
            singleLine=true;
            layout_marginLeft="5dp";
          };
          {
            TextView;
            id="湿度text";
            text="湿度 未知";
            layout_marginLeft="5dp";
            singleLine=true;
          };
          {
            TextView;
            id="风力风向text";
            text="风力 未知";
            singleLine=true;
            layout_marginLeft="5dp";
          };
        };
        {
          LinearLayout;
          layout_marginTop="0%h";
          layout_gravity="center";
          layout_width="20%w";
          layout_height="0%h";
          background="#00FFFFFF";
          orientation="vertical";
          {
            ImageView;
            layout_width="20%w";
            -- src="img/google.png";
            scaleType="fitXY";
            layout_height="10%h";
            id="yq";
          };
        };
      };
      {
        CardView;
        layout_marginTop="3%h";
        layout_margin="0%h";
        layout_width="95%w";
        radius="3dp";
        elevation="0%h";
        layout_height="wrap_content";
        CardBackgroundColor="#000000";
        layout_gravity="center";
        {
          TextView;
          textSize="10dp";
          layout_width="fill";
          gravity="right";
          text="Good recommendation.";
          layout_marginRight="1%h";
          layout_height="wrap_content";
          textColor="#99ffffff";
        };
      };
      {
        CardView;
        layout_margin="0%h";
        layout_width="fill";
        radius="0%h";
        elevation="0%h";
        layout_height="wrap_content";
        CardBackgroundColor="#00000000";
        layout_gravity="center";
        {
          HorizontalScrollView;
          layout_width="fill";
          layout_height="fill";
          {
            LinearLayout;
            background="#00000000";
            layout_height="fill";
            layout_width="fill";
            orientation="horizontal";
            {
              CardView;
              id="a1";
              layout_margin="1%h";
              layout_width="wrap_content";
              radius="1%h";
              elevation="0%h";
              layout_height="fill";
              CardBackgroundColor="#00000000";
              layout_gravity="center";
              {
                LinearLayout;
                background="#00000000";
                layout_height="fill";
                layout_width="fill";
                orientation="vertical";
                {
                  ImageView;
                  layout_gravity="center";
                  layout_width="7%h";
                  src="drawable/b.png";
                  scaleType="fitXY";
                  layout_height="7%h";
                  id="help";
                };
                {
                  TextView;
                  layout_width="fill";
                  gravity="center";
                  textSize="10dp";
                  layout_height="wrap_content";
                  text="功能一";
                  textColor="#99000000";
                };
              };
            };
            {
              CardView;
              id="a2";
              layout_margin="1%h";
              layout_width="wrap_content";
              radius="1%h";
              elevation="0%h";
              layout_height="fill";
              CardBackgroundColor="#00000000";
              layout_gravity="center";
              {
                LinearLayout;
                background="#00000000";
                layout_height="fill";
                layout_width="fill";
                orientation="vertical";
                {
                  ImageView;
                  layout_gravity="center";
                  layout_width="7%h";
                  src="drawable/c.png";
                  scaleType="fitXY";
                  layout_height="7%h";
                  id="Rank";
                };
                {
                  TextView;
                  layout_width="fill";
                  gravity="center";
                  textSize="10dp";
                  layout_height="wrap_content";
                  text="功能二";
                  textColor="#99000000";
                };
              };
            };
            {
              CardView;
              id="a3";
              layout_margin="1%h";
              layout_width="wrap_content";
              radius="1%h";
              elevation="0%h";
              layout_height="fill";
              CardBackgroundColor="#00000000";
              layout_gravity="center";
              {
                LinearLayout;
                background="#00000000";
                layout_height="fill";
                layout_width="fill";
                orientation="vertical";
                {
                  ImageView;
                  layout_gravity="center";
                  layout_width="7%h";
                  src="drawable/d.png";
                  scaleType="fitXY";
                  layout_height="7%h";
                  id="video";
                };
                {
                  TextView;
                  layout_width="fill";
                  gravity="center";
                  textSize="10dp";
                  layout_height="wrap_content";
                  text="功能三";
                  textColor="#99000000";
                };
              };
            };
            {
              CardView;
              id="a4";
              layout_margin="1%h";
              layout_width="wrap_content";
              radius="1%h";
              elevation="0%h";
              layout_height="fill";
              CardBackgroundColor="#00000000";
              layout_gravity="center";
              {
                LinearLayout;
                background="#00000000";
                layout_height="fill";
                layout_width="fill";
                orientation="vertical";
                {
                  ImageView;
                  layout_gravity="center";
                  layout_width="7%h";
                  src="drawable/e.png";
                  scaleType="fitXY";
                  layout_height="7%h";
                  id="book";
                };
                {
                  TextView;
                  layout_width="fill";
                  gravity="center";
                  textSize="10dp";
                  layout_height="wrap_content";
                  text="功能四";
                  textColor="#99000000";
                };
              };
            };
            {
              CardView;
              id="a7";
              layout_margin="1%h";
              layout_width="wrap_content";
              radius="1%h";
              elevation="0%h";
              layout_height="fill";
              CardBackgroundColor="#00000000";
              layout_gravity="center";
              {
                LinearLayout;
                background="#00000000";
                layout_height="fill";
                layout_width="fill";
                orientation="vertical";
                {
                  ImageView;
                  layout_gravity="center";
                  layout_width="7%h";
                  src="drawable/f.png";
                  scaleType="fitXY";
                  layout_height="7%h";
                  id="tool";
                };
                {
                  TextView;
                  layout_width="fill";
                  gravity="center";
                  textSize="10dp";
                  layout_height="wrap_content";
                  text="功能五";
                  textColor="#99000000";
                };
              };
            };
            {
              CardView;
              id="a6";
              layout_margin="1%h";
              layout_width="wrap_content";
              radius="1%h";
              elevation="0%h";
              layout_height="fill";
              CardBackgroundColor="#00000000";
              layout_gravity="center";
              {
                LinearLayout;
                background="#00000000";
                layout_height="fill";
                layout_width="fill";
                orientation="vertical";
                {
                  ImageView;
                  layout_gravity="center";
                  layout_width="7%h";
                  src="drawable/g.png";
                  scaleType="fitXY";
                  layout_height="7%h";
                  id="sett";
                };
                {
                  TextView;
                  layout_width="fill";
                  gravity="center";
                  textSize="10dp";
                  layout_height="wrap_content";
                  text="功能六";
                  textColor="#99000000";
                };
              };
            };
            {
              CardView;
              id="a8";
              layout_margin="1%h";
              layout_width="wrap_content";
              radius="1%h";
              elevation="0%h";
              layout_height="fill";
              CardBackgroundColor="#00000000";
              layout_gravity="center";
              {
                LinearLayout;
                background="#00000000";
                layout_height="fill";
                layout_width="fill";
                orientation="vertical";
                {
                  ImageView;
                  layout_gravity="center";
                  layout_width="7%h";
                  src="drawable/h.png";
                  scaleType="fitXY";
                  layout_height="7%h";
                  id="Resolution";
                };
                {
                  TextView;
                  layout_width="fill";
                  gravity="center";
                  textSize="10dp";
                  layout_height="wrap_content";
                  text="功能七";
                  textColor="#99000000";
                };
              };
            };
          };
        };
      };
      {
        CardView;
        id="ppp";
        layout_margin="0%h";
        layout_width="95%w";
        radius="3dp";
        elevation="0%h";
        layout_height="wrap_content";
        CardBackgroundColor="#000000";
        layout_gravity="center";
        {
          TextView;
          textSize="10dp";
          layout_width="fill";
          gravity="left";
          text="Daily sentence";
          layout_height="wrap_content";
          textColor="#99ffffff";
          layout_marginLeft="1%h";
        };
      };
      {
        CardView;
        layout_marginTop="2%h";
        layout_margin="0%h";
        layout_marginBottom="2%h";
        elevation="0%h";
        CardBackgroundColor="#00999999";
        layout_width="95%w";
        layout_height="wrap_content";
        radius="0.5%h";
        layout_gravity="center";
        {
          TextView;
          textSize="10dp";
          layout_margin="2%h";
          layout_width="fill";
          gravity="left";
          id="yiyan";
          text="正在获取今日份一言……";
          layout_height="wrap_content";
          layout_gravity="center";
          textColor="#99000000";
        };
      };
      {
        CardView;
        layout_margin="0%h";
        layout_width="95%w";
        radius="3dp";
        elevation="0%h";
        layout_height="wrap_content";
        CardBackgroundColor="#000000";
        layout_gravity="center";
        {
          TextView;
          layout_width="fill";
          gravity="center";
          textSize="10dp";
          layout_height="wrap_content";
          text="Nov."..os.date("%Y-%m-%d");
          textColor="#99ffffff";
        };
      };
    };
  };
};
activity.setContentView(loadlayout(wux))


activity.setRequestedOrientation(1);


function CircleButton(view,InsideColor,radiu)
  import "android.graphics.drawable.GradientDrawable"
  drawable = GradientDrawable() 
  drawable.setShape(GradientDrawable.RECTANGLE) 
  drawable.setColor(InsideColor)
  drawable.setCornerRadii({radiu,radiu,radiu,radiu,radiu,radiu,radiu,radiu});
  view.setBackgroundDrawable(drawable)
end
CircleButton(cdd,0x00000000,360)
CircleButton(bity1,0x00000000,360)
CircleButton(bity2,0x00000000,360)
CircleButton(wk,0x00000000,360)

function CircleButton(view,InsideColor,radiu)
  import "android.graphics.drawable.GradientDrawable"
  drawable = GradientDrawable() 
  drawable.setShape(GradientDrawable.RECTANGLE) 
  drawable.setColor(InsideColor)
  drawable.setCornerRadii({radiu,radiu,radiu,radiu,radiu,radiu,radiu,radiu});
  --     view.setBackgroundDrawable(drawable)
end
角度=180
控件id=xu
控件颜色=0x0009639C
CircleButton(控件id,控件颜色,角度)
color1 = 0xffe71e62;
color2 = 0x00000000;
天气网链接="https://m.tianqi.com/"
中国天气网链接="https://m.weather.com.cn/"
天气源=1 --1天气网,2中国天气网
--天气网的天气获取
Http.get(天气网链接,nil,"utf8",nil,function(code,content,cookie,header)
  if(code==200 and content)then
    定位城市=content:match("<text>(.-)</text>")
    湿度=content:match('<span class="b2"><i></i>湿度(.-)</span')
    空气质量=content:match('<div class="info"><span class="b1"><i></i>(.-)</span')
    风力风向=content:match('<span class="b3"><i></i>(.-)</span>')
    度数=content:match('<dd class="now">(.-)<i>')
    详细=content:match('<dd class="txt">(.-)</dd>')
    天气图标=content:match('<dt><img src="(.-)"></dt>')
    天气icon.setImageBitmap(loadbitmap("https://m.tianqi.com/"..天气图标))
    温度text.text=度数.."℃"
    温度数据text.text=详细
    当前城市text.text=定位城市
    湿度text.text="湿度"..湿度
    风力风向text.text=风力风向
    天气icon.setColorFilter(0x00000000)
  else
    天气icon.setColorFilter(0xff000000)
    天气icon.setImageBitmap(loadbitmap("drawable/unknown.png"))
    温度text.text="-- ℃"
    温度数据text.text="未知温度"
    当前城市text.text=" "
    --  空气质量text.text=" "
    湿度text.text="无法获取天气信息, 刷新或检查网络"
    风力风向text.text=" "
  end
end)
if tonumber(os.date("%H"))>=tonumber("23") then
  asp3.setText("半夜")
elseif tonumber(os.date("%H"))>=tonumber("19") then
  asp3.setText("晚上")
elseif tonumber(os.date("%H"))>=tonumber("17") then
  asp3.setText("傍晚")
elseif tonumber(os.date("%H"))>=tonumber("14") then
  asp3.setText("下午")
elseif tonumber(os.date("%H"))>=tonumber("12") then
  asp3.setText("中午")
elseif tonumber(os.date("%H"))>=tonumber("10") then
  asp3.setText("上午")
elseif tonumber(os.date("%H"))>=tonumber("7") then
  asp3.setText("早上")
elseif tonumber(os.date("%H"))<=tonumber("5") then
  asp3.setText("凌晨")
end
Http.get("http://m.wufazhuce.com/",nil,nil,nil,function(code,content)
  if code==200 then
    一个一言=content:match([[<p%sclass="text%pcontent%pshort"%sid="quote">(.-)</p>]])
    --  一个图片=content:match([[<div%sclass="home%pimg"%sstyle="background%pimage:url%p(.-)%p">]])
    yiyan.text=一个一言

  else
    yiyan.text="可能是网络或者第三方服务器原因,今日份一言获取失败了哦!"
  end
end)

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,907评论 6 506
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,987评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,298评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,586评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,633评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,488评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,275评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,176评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,619评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,819评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,932评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,655评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,265评论 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,871评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,994评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,095评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,884评论 2 354

推荐阅读更多精彩内容