简约便捷的音天气预报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"

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

被折叠的 条评论
为什么被折叠?



