简单的天气预报app

本文介绍了作者如何创建一个简单的天气预报App。使用了百度天气API获取数据,通过HttpURLConnection发送网络请求,并对返回的JSON数据进行解析。解析后的数据更新在UI界面上,实现天气信息的显示。源码已上传至GitHub,欢迎查阅。

简约便捷的音天气预报app

自己最近慢慢摸索写了一个简约便捷的天气预报app,先发上来供大家参考和自己复习学习。这里写图片描述这里写图片描述## api ##首先我们需要一个api,我采用的是百度天气的api,具体步骤大家可以参考http://lbsyun.baidu.com/index.php?title=car/api/weather

xml布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/bj2"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="80dp"
        android:orientation="horizontal">
        <ImageView
            android:id="@+id/imgtop"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/duoyun"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="20dp"
            />
        <TextView
            android:id="@+id/wendu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="50dp"
            android:layout_marginTop="20dp"
            android:textColor="@color/colorAccent"
            />
        <EditText
            android:id="@+id/etcityname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:textColor="#ffffff"
            android:hint="输入城市名称"
            android:textColorHint="#ffffff"
            android:textSize="24dp"/>
        <Button
            android:id="@+id/sousuo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="24dp"
            android:textColor="#ffffff"
            android:text="搜索"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal"
        android:gravity="center">
        <TextView
            android:id="@+id/date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#ffffff"
            />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:gravity="center">
        <TextView
            android:id="@+id/city"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="80dp"
            android:textColor="#ffffff"/>
    </LinearLayout>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#ffffff"/>
<ScrollView
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="100dp"
       android:layout_marginTop="5dp"
       android:orientation="horizontal">
       <LinearLayout
           android:layout_width="0dp"
           android:layout_weight="1"
           android:layout_height="match_parent"
           android:orientation="vertical">
           <TextView
               android:layout_width="match_parent"
               android:layout_height="30dp"
               android:text="wind"
               android:gravity="center"
               android:textColor="#ffffff"
               android:textSize="20dp"/>
           <TextView
               android:id="@+id/wind"
               android:layout_width="match_parent"
               android:layout_height="60dp"
               android:textSize="20dp"
               android:textColor="#ffffff"
               android:gravity="center"/>
       </LinearLayout>
       <TextView
           android:layout_width="1dp"
           android:layout_height="match_parent"
           android:background="#55000000" />
       <LinearLayout
           android:layout_width="0dp"
           android:layout_weight="1"
       
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值