天气预报案例

这是一个Android天气预报应用的详细实现案例,包括资源文件、代码、清单文件和执行流程。资源文件包括各种布局XML,如activity_main.xml。代码部分涵盖访问天气网址、解析天气信息、WeatherService、DateUtil等多个类。在清单文件AndroidManifest.xml中,设置了应用图标、主题等。执行流程涉及显示天气、添加城市、选择城市显示详情、刷新天气和保存城市信息列表等功能。
摘要由CSDN通过智能技术生成

天气预报案例代码:

 

1 资源文件

     

 

1 资源文件                             2 图片

                                                             

 

各布局文件代码如下:

1activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="zhaohuanhuan.cn.weather.MainActivity"
    android:orientation="vertical"
    >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="347dp"
        android:background="#9d9dd7">

        <TextView
            android:id="@+id/tv_city"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="10dp"
            android:text="淄博"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/tv_country"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/tv_city"
            android:layout_alignBottom="@+id/tv_city"
            android:layout_marginLeft="10dp"
            android:text="中国"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/tv_currentdate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/tv_city"
            android:layout_below="@+id/tv_city"
            android:layout_marginTop="5dp"
            android:text="47日,星期五" />

        <ImageView
            android:id="@+id/iv_condflag"
            android:layout_width="60dp"
            android:layout_height="50dp"
            android:layout_alignLeft="@+id/tv_city"
            android:layout_below="@+id/tv_currentdate"
            android:layout_marginTop="5dp"
            android:src="@mipmap/ic_launcher" />

        <TextView
            android:id="@+id/tv_currenttemp"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_alignTop="@+id/iv_condflag"
            android:layout_marginLeft="10dp"
            android:layout_toRightOf="@+id/iv_condflag"
            android:gravity="center"
            android:text="20oC"
            android:textSize="30sp" />

        <ImageView
            android:id="@+id/iv_up"
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:layout_alignTop="@+id/iv_condflag"
            android:layout_marginLeft="7dp"
            android:layout_toRightOf="@+id/tv_currenttemp"
            android:src="@drawable/arrow_up" />

        <TextView
            android:id="@+id/tv_hightemp"
            android:layout_width="wrap_content"
            android:layout_height="25dp"
            android:layout_alignTop="@+id/iv_condflag"
            android:layout_marginLeft="7dp"
            android:layout_toRightOf="@+id/iv_up"
            android:gravity="center"
            android:text="25oC" />

        <ImageView
            android:id="@+id/iv_down"
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:layout_alignBottom="@+id/iv_condflag"
            android:layout_marginLeft="7dp"
            android:layout_toRightOf="@+id/tv_currenttemp"
            android:src="@drawable/arrow_down" />

        <TextView
            android:id="@+id/tv_lowtemp"
            android:layout_width="wrap_content"
            android:layout_height="25dp"
            android:layout_alignBottom="@+id/iv_condflag"
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@+id/iv_up"
            android:gravity="center"
            android:text="15oC" />

        <TextView
            android:id="@+id/tv_currentcond"
            android:layout_width="60dp"
            android:layout_height="30dp"
            android:layout_alignLeft="@+id/iv_condflag"
            android:layout_below="@+id/iv_condflag"
            android:layout_marginTop="10dp"
            android:gravity="center"
            android:text="多云"
            android:textSize="20sp" />

        <ImageView
            android:id="@+id/iv_hum"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_alignLeft="@+id/iv_condflag"
            android:layout_below="@+id/tv_currentcond"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="30dp"
            android:src="@drawable/hum" />

        <TextView

            android:layout_width="wrap_content"
            android:layout_height="20dp"
            android:layout_alignTop="@+id/iv_hum"
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@+id/iv_hum"
            android:text="湿度" />

        <TextView
            android:id="@+id/tv_hum"
            android:layout_width="wrap_content"
            android:layout_height="20dp"
            android:layout_alignBottom="@+id/iv_hum"
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@id/iv_hum"
            android:text="55%" />


        <!--1天天气-->
        <TextView
            android:id="@+id/tv_firstdate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/iv_hum"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="20dp"
            android:text="47,星期五" />

        <ImageView
            android:id="@+id/iv_firstcond"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_alignLeft="@+id/tv_firstdate"
            android:layout_below="@+id/tv_firstdate"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:src="@mipmap/ic_launcher" />

        <TextView
            android:id="@+id/tv_firsthigh"
            android:layout_width="wrap_content"
            android:layout_height="20dp"
            android:layout_below="@+id/tv_firstdate"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:layout_toRightOf="@+id/iv_firstcond"
            android:text="25oC" />

        <TextView
            android:id="@+id/tv_firstlow"
            android:layout_width="wrap_content"
            android:layout_height="20dp"
            android:layout_below="@+id/tv_firsthigh"
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@+id/iv_firstcond"
            android:text="15oC" />

        <!--2天天气-->
        <TextView
            android:id="@+id/tv_seconddate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/iv_hum"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="20dp"
            android:layout_toRightOf="@id/tv_firstdate"
            android:text="48,星期六" />

        <ImageView
            android:id="@+id/iv_secondcond"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_alignLeft="@+id/tv_seconddate"
            android:layout_below="@+id/tv_seconddate"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:src="@mipmap/ic_launcher" />

        <TextView
            android:id="@+id/tv_secondhigh"
            android:layout_width="wrap_content"
            android:layout_height="20dp"
            android:layout

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值