Android笔记(十一) Android中的布局——网格布局
网格布局是Android4.0新增的布局管理器,因此需要在Android4.0之后的版本才可以使用,之前的平台使用该布局的话,需要导入相应的支持库。
GridLayout的作用类似于HTML中的table标签,它把整个容器划分成row*column个网格,每个网格都可以放置一个组件,也可以设置一个组件横跨多少列、多少行。
GridLayout提供了setRowCount(int)和setColumnCount(int)方法来控制该网格的行数和列数。
简单代码示例:
gridlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="6"
android:columnCount="4"
android:id="@+id/root"> <!-- 定一个一个横跨四列的文本框,并设置该文本框的前景色、背景色等属性 -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_columnSpan="4"
android:textSize="50sp"
android:layout_marginLeft="4px"
android:layout_marginRight="4px"
android:padding="5px"
android:layout_gravity="right"
android:background="#eee"
android:textColor="#000"
android:text="0"
/>
<!-- 定义一个横跨四列的按钮 -->
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_columnSpan="4"
android:text="清除"/> <!-- 添加其他按钮 -->
<Button
android:text="7"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:text="8"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:text="9"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:text="/"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:text="4"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:text="5"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:text="6"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:text="*"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:text="1"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:text="2"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:text="3"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:text="-"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:text="0"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:text="."
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:text="+"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:text="="
android:layout_rowWeight="1"
android:layout_columnWeight="1"/> </GridLayout>
运行结果:

Android笔记(十一) Android中的布局——网格布局的更多相关文章
- Android 笔记之 Android 系统架构
Android笔记之Android系统架构 h2{ color: #4abcde; } a{ color: blue; text-decoration: none; } a:hover{ color: ...
- Python pyQt4/PyQt5 学习笔记3(绝对对位,盒布局,网格布局)
本节研究布局管理的内容. (一)绝对对位 import sys from PyQt4 import QtGui class Example(QtGui.QWidget): def __init__( ...
- Android进阶(十一)Android系统架构讲解
如果说一个成功男人的背后会有一个默默支持的女人的话,那么一个优越稳定的平台背后必有一个成熟的系统架构所支撑着.那么,Android的系统架构是怎么样的呢?从下图我们可以从整体上有个大致的了解(图片来源 ...
- Android 基础 十一 Android的消息机制
Handler是Android消息机制的上层接口,这使得在开发应用过程中我们只需要和Handler交互即可.Handler的使用过程很简单,通过它可以轻松地将一个任务切换到Handler所在的线程中去 ...
- Android笔记: Android版本号
由于有2套版本号 总是对应不准 记下来做过标记 Android 4.3 ----18 Android 4.2---17 Android 4.1---16 Android 4.0.3---15Andro ...
- Android笔记:java 中的数组
在与嵌入式设备通讯的过程中使用的socket通讯 获取的字节流,通常转换为字节数组,需要根据协议将字节数组拆分.对于有规律的重复拆分可以使用,由于java中不能像c中直接进行内存操作例如使用struc ...
- Android笔记:java 中的枚举
部分数据使用枚举比较方便,java中的enmu不如c#中使用方便 记录备忘 以c#中的代码为例 public enum PlayState { /// <summary> /// 关闭 / ...
- Android笔记之Fragment中创建ViewModel的正确方式
之前一直都是这么写的 pageViewModel = ViewModelProviders.of(this).get(PageViewModel.class); //参数this是当前fragment ...
- Java学习笔记十一:Java中的方法
Java中的方法 一:什么是方法: 所谓方法,就是用来解决一类问题的代码的有序组合,是一个功能模块. 学过C语言或者其他语言的应该都知道函数这个东西,在Java中,其实方法就是函数,只不过叫法不同,在 ...
随机推荐
- Spring MVC入门的实例
作为Spring MVC入门,以XML配置的方式为例.首先需要配置Web工程的web.xml文件. 代码清单14-1:web.xml配置Spring MVC <?xml version=&q ...
- [ kvm ] 学习笔记 9:WebVirtMgr 基础及安装使用
目录- 1. 前言- 2. webvirtmgr 简介- 3. webvirtmgr 部署实践 - 3.1 配置 webvirtmgr 主机 - 3.2 kvm node节点配置 - ...
- Django: ORM查询中使用or查询
先引入Q,(原名就叫Q) from django.db.models import Q page_user = User.objects.filter(Q(member_code__contains= ...
- solr关于日期范围查询
问题:从solr上查询创建日期在2019-06-25到2019-06-26之间的数据 createDate:[2019-06-25 TO 2019-06-26]
- Java中的IO流之输出流|乐字节
大家好,乐字节小乐又来了.上一篇给大家带来的是:Java中的IO流之输入流|乐字节,本文将继续讲述IO流之输出流. 一.输出流 1.抽象类:OutputStream 和 Writer Output ...
- [bzoj4240]有趣的家庭菜园_树状数组
有趣的家庭菜园 题目链接:https://lydsy.com/JudgeOnline/problem.php?id=4240 数据范围:略. 题解: 第一步比较简单,只需要排序之后,每个数不是在左边就 ...
- Flink状态管理和容错机制介绍
本文主要内容如下: 有状态的流数据处理: Flink中的状态接口: 状态管理和容错机制实现: 阿里相关工作介绍: 一.有状态的流数据处理# 1.1.什么是有状态的计算# 计算任务的结果不仅仅依赖于输入 ...
- js取小数点后两位数的方法
四舍五入以下处理结果会四舍五入:toFixed( ) var num =2.446242342; num = num.toFixed(2); // 输出结果为 2.45 不四舍五入以下处理结果不会四舍 ...
- 传输json数据到前台的时候,数据中包含日期数据
问题描述 当从数据库中查询的数据中包含有日期格式的数据的时候,数据传输到前台会报错. 解决方式 // 逐条将日期进行格式化后再传输 Date date = new SimpleDateFormat(& ...
- [转帖]MySQL的又一神器-锁,MySQL面试必备
MySQL的又一神器-锁,MySQL面试必备 https://segmentfault.com/a/1190000020762791 lock 低一级的是 latch 原文链接:blog.ouya ...