极简天气app

最近在学习Android,这里就用这个极简天气app练练手吧。

虽然简陋,但是我们将学习以下内容:

  • Android单线程模型
  • 两个Activity之间传递数据
  • 异步类AsyncTask
  • 数据结构Map
  • Json格式解析
  • 多级联动的滚轮

制作思路:

  1. UI布局
  2. 城市选择
  3. 对应城市天气数据获取与处理
  4. 刷新UI

先看看效果吧(前面有点迟钝):

我点击右上角的城市管理按钮后进入城市选择(里面的城市是随便写的哦),确认后返回主界面,这里只显示高温而已。

确实极简吧,但是其中的处理过程可是一点没有少的!是要少加布局上的修饰就瞬间高大上了。

先看布局文件(activity_main.xml):

@+id/activity_main_textview_city这是用于显示我们选择的城市的TextView。

@+id/activity_main_textview_content这是显示天气内容的TextView(我偷懒把所有的内容都放进去了,嘿嘿,嘿嘿)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/activity_main_button_chengshiguanli"
        android:layout_width="50dp"
        android:layout_height="25dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp"
        android:text="@string/chengshiguanli"
        android:background="@color/colorWhite"
        android:textSize="5pt"/>

    <TextView
        android:id="@+id/activity_main_textview_city"
        android:layout_width="150dp"
        android:layout_height="50dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:textSize="17pt"
        android:gravity="center"
    />

    <TextView
        android:id="@+id/activity_main_textview_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/activity_main_textview_city"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="10dp"
        />
</RelativeLayout>

下面是选择城市的布局文件(choose_city.xml):

其中我们用到了com.wx.wheelview.widget.WheelView组件,这是一个开源的滚轮组件,使用之前需要先导入相应的包,这里是其项目地址和详细的使用说明:https://github.com/venshine/WheelView

"@+id/city_btn",android:text="boom" 这个按钮是我们做测试用的。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
   >

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.wx.wheelview.widget.WheelView
            android:id="@+id/wheel_province"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>

        <com.wx.wheelview.widget.WheelView
            android:id="@+id/wheel_city"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>

        <com.wx.wheelview.widget.WheelVi
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值