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

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

作者: Ktry | 来源:发表于2020-02-28 13:09 被阅读0次

    什么是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)
    
    

    相关文章

      网友评论

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

          本文链接:https://www.haomeiwen.com/subject/bbakhhtx.html