[android] 天气app布局练习(二)
主要练习一下GridView

MainActivity.java
package com.example.weatherreport; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import android.app.Activity;
import android.os.Bundle;
import android.widget.GridView;
import android.widget.SimpleAdapter; public class MainActivity extends Activity {
private GridView gv_airs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gv_airs=(GridView) findViewById(R.id.gv_airs);
makeGridView();
}
/**
* 组装GridView
*/
private void makeGridView() {
List<Map<String, String>> data=new ArrayList<>();
Map<String,String> item=null;
item=new HashMap<>();
item.put("title", "83");
item.put("desc", "湿度(%)");
data.add(item); item=new HashMap<>();
item.put("title", "11.3");
item.put("desc", "可见度(km)");
data.add(item); item=new HashMap<>();
item.put("title", "2级");
item.put("desc", "东南风");
data.add(item); item=new HashMap<>();
item.put("title", "最弱");
item.put("desc", "紫外线");
data.add(item); item=new HashMap<>();
item.put("title", "1005.5");
item.put("desc", "气压(mb)");
data.add(item); item=new HashMap<>();
item.put("title", "22.4");
item.put("desc", "体感");
data.add(item); SimpleAdapter adapter=new SimpleAdapter(this, data, R.layout.main_grid_item, new String[]{"title","desc"}, new int[]{R.id.tv_title,R.id.tv_desc});
gv_airs.setAdapter(adapter);
}
}
activity_main.xml
<RelativeLayout 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"
android:background="#3186D9"
tools:context="${relativePackage}.${activityClass}" > <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:src="@drawable/icon_home" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:text="北京"
android:textColor="#FDFDFD" /> <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:src="@drawable/icon_more" /> <TextView
android:id="@+id/tv_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:text="29"
android:textColor="#fff"
android:textSize="50sp" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/tv_number"
android:layout_toRightOf="@id/tv_number"
android:text="°"
android:textColor="#FDFDFD"
android:textSize="30sp" /> <LinearLayout
android:id="@+id/ll_weather"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_number"
android:layout_centerHorizontal="true"
android:orientation="horizontal" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="多云"
android:textColor="#FDFDFD" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text=" | "
android:textColor="#bbb" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="空气优"
android:textColor="#FDFDFD" />
</LinearLayout> <View
android:id="@+id/gv_airs_top"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/ll_weather"
android:layout_marginTop="20dp"
android:background="#ddd" /> <GridView
android:id="@+id/gv_airs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/gv_airs_top"
android:background="#ddd"
android:horizontalSpacing="1dp"
android:listSelector="@android:color/transparent"
android:numColumns="3"
android:verticalSpacing="1dp" /> <View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/gv_airs"
android:background="#ddd" /> </RelativeLayout>
main_grid_item.xml
<?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"
android:background="#3186D9"
android:layout_marginLeft="1dp" > <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="25dp"
android:paddingBottom="25dp"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical" > <TextView
android:id="@+id/tv_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="湿度(%)"
android:textColor="#ddd"
android:textSize="12sp" /> <TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="83"
android:textColor="#fff"
android:textSize="22sp" />
</LinearLayout> </RelativeLayout>
[android] 天气app布局练习(二)的更多相关文章
- [android] 天气app布局练习(四)
主要练习一下获取网络数据和解析xml MainActivity.java package com.example.weatherreport; import java.io.UnsupportedEn ...
- [android] 天气app布局练习(三)
主要练习LinearLayout和layout_weight属性 <RelativeLayout xmlns:android="http://schemas.android.com/a ...
- [android] 天气app布局练习
主要练习一下RelativeLayout和LinearLayout <RelativeLayout xmlns:android="http://schemas.android.com/ ...
- 制作一个功能丰富的Android天气App
简易天气是一个基于和风天气数据采用MD设计的Android天气App.目前的版本采用传统的MVC模式构建.通过丰富多彩的页面为用户提供日常所需的天气资讯. 项目说明 项目放在github上面 地址是: ...
- [Android]天气App 2 项目搭建
对于天气App,为了简化一些功能,暂时模仿MUUI系统提供的那个App. 本项目需要引入本人经常使用的一个工具库DroidTool,这个是本人根据工作中,收集到一些工具类,下载地址. ...
- [Android]天气App 3 网络数据的请求和Json解析
Android客户端开发,不仅仅是在Android端开发,还需要有相应的后台服务支持,否则的话,客户端的数据就只能放到本地自己做处理.我认为的原生态的App就是对应服务端的Client.他能像浏览 ...
- [Android]天气App 1
闲赋在家,无事可做就想着做点东西,于是乎把玩手机,我最常用的就是看天气,基本上我每天起来第一件事就是看天气,哈哈,用别人的这么爽,为什么不自己整一个关于天气的应用呢,墨迹天气.小米系统自带的天气.ya ...
- Android学习系列(5)--App布局初探之简单模型
人类科技的进步源自探索,探索来自于发现本原,当然App布局没这么先进,本文也只是一个归类总结.这篇文章是Android开发人员的必备知识,是我特别为大家整理和总结的,不求完美,但是有用. Androi ...
- Android APP压力测试(二)之Monkey信息自动收集脚本
Android APP压力测试(二) 之Monkey信息自动收集脚本 前言: 上一篇Monkey介绍基本搬抄官方介绍,主要是为了自己查阅方便.本文重点介绍我在进行Monkey时如何自动收集相关信息 ...
随机推荐
- animal与@keyframe
.test1 { width: 90px; height: 60px; -webkit-animation-name: skyset; -webkit-animation-duration: 2000 ...
- opencv学习笔记(七)---图像金字塔
图像金字塔指的是同一图像不同分辨率的子图的集合,有向下取样金字塔,向上取样金字塔,拉普拉斯金字塔....它是图像多尺度表达的一种,最主要的是用于图像的分割 向下取样金字塔指高分辨率图像向低分辨率图像的 ...
- NavigationItem的Title不居中,BackButton修改它得title
国外得一个链接: http://situee.blogspot.com/2014/10/ios-set-navigation-bar-back-button-title.html 最近迷上了简洁风,在 ...
- tomcat 搭建以及发布配置
身为开发人员, 一直干着开发的事情, 只干开发的事情, 却缺少了对于环境部署方面的必备技能的培养, 所以在公司安排的手头任务解决完的情况下, 自己抽空了解并且实践了一下tomcat的配置.写下通过网络 ...
- 进阶篇:4)面向装配的设计DFA总章
本章目的:理解装配的重要性,明确结构工程师也要对装配进行设计. 1.基础阅读 ①进阶篇:1)DFMA方法的运用: ②需要一台FDM3d打印机:请查看 基础篇:8)结构设计装备必备: 2.为什么要学习D ...
- css3 实现 tooltip
/* START TOOLTIP STYLES */ [tooltip] { position: relative; /* opinion 1 */ } /* Applies to all toolt ...
- Python——爬取百度百科关键词1000个相关网页
Python简单爬虫——爬取百度百科关键词1000个相关网页——标题和简介 网站爬虫由浅入深:慢慢来 分析: 链接的URL分析: 数据格式: 爬虫基本架构模型: 本爬虫架构: 源代码: # codin ...
- 如何在vue中请求本地json文件
1..修改webpack.base.conf.js 文件中添加'/static': resolve('static'),如下所示,此时存放于static的json文件就可以通过/static/xxx. ...
- 读取obj文件用Mesh创建实例化
using UnityEngine; using System.Collections; using System.IO; using System.Collections.Generic; usin ...
- mvc Area(区域)相关技术
ASP.NET MVC中,是依靠某些文件夹以及类的固定命名规则去组织model实体层,views视图层和控制层的.如果是大规模的应用程序,经常会由不同功能的模块组成,而每个功能模块都由MVC中的三层所 ...