天气预报的简单制作(二)
来源:互联网 发布:vbs 读取网页源码 编辑:程序博客网 时间:2024/06/03 19:01
承接上文天气预报的简单制作(一)
4、设置权限
<uses-permission android:name="android.permission.INTERNET"/>
5、显示天气信息(实体类)
定义GSON实体类(basic、aqi、now、suggestion和daily_forecast)在gson中建立basic、aqi、suggestion、now和forecast。并新建weather来对这些进行引用。
(1)为什么借助GSON来对天气信息进行解析而不用JSONObject?
因为和风天气中返回的JSON数据结构非常复杂,如果用JSONObject来解析就会非常麻烦。
(2)在这里用得上key值,参数中传来的天气id和我们之前申请的key值拼装成一个接口地址并调用解析数据。
6、手动更新天气和切换城市
(1)下拉刷新菜单
在写好的布局代码中加入SwipeRefreshLayout,再在主函数中加入更新天气的处理逻辑这样就可以了,很简单吧!!
<?xml version="1.0" encoding="utf-8"?><!--将先前的天气界面各部分的布局文件引入--><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorPrimary"> <ImageView android:id="@+id/bing_pic_img" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" /> <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!--在ScrollView在嵌套一个SwipeRefreshLayout就可以下拉刷新--> <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipe_refresh" android:layout_width="match_parent" android:layout_height="match_parent"> <ScrollView android:id="@+id/weather_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="none" android:overScrollMode="never"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true"> <include layout="@layout/title" /> <include layout="@layout/now" /> <include layout="@layout/forecast" /> <include layout="@layout/aqi" /> <include layout="@layout/suggestion" /> </LinearLayout> </ScrollView> </android.support.v4.widget.SwipeRefreshLayout> <fragment android:id="@+id/choose_area_fragment" android:name="com.coolweather.android.ChooseAreaFragment" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="start" /> </android.support.v4.widget.DrawerLayout></FrameLayout>(2)切换城市
在之前遍历全国省市县的数据完成的前提下只需要在天气布局中引用即可,这样就可以快速切换城市的功能。
(3)后台自动更新天气
要想实现这个功能就需要创建一个长期在后台运行的定时任务。
7、修改图标和名称并仔细检查代码
这就按照你的喜好,这就完成了。
阅读全文
0 0
- 天气预报的简单制作(二)
- 天气预报的简单制作(一)
- 简单的天气预报 (二)
- android制作一个简单的天气预报
- 简单的android天气预报
- 简单的天气预报 (一)
- 简单的天气预报 (三)
- 简单的天气预报 (四)
- 简单的天气预报 (五)
- 简单的天气预报 (六)
- Android简单的天气预报
- 一个简单的天气预报
- 简单的天气预报app
- android天气预报(二)
- 使用PlayCanvas制作一个简单的小游戏(二)
- OpenlGL游戏编程-简单的机器人制作(二)
- 【python 天气预报】python制作属于自己的天气预报
- 一个简单的java天气预报
- JS组件系列——Bootstrap 树控件使用经验分享
- 整合spring cloud云服务架构代码结构构建
- Hash索引和BTree索引
- android 捕获Enter键的点击事件
- CGAffineTransformMakeScale
- 天气预报的简单制作(二)
- 分录相关操作
- [一图一世界] 从2017年Amazon年Q3财报看市场趋势
- CSS 使用 贝塞尔曲线 碰撞效果实现
- JS组件系列——Form表单验证神器: BootstrapValidator
- Spring Cloud云服务架构
- DHCP(二)
- python 入门关键字随笔
- VS2015 + Qt5.7 环境搭建