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中,其实方法就是函数,只不过叫法不同,在 ...
随机推荐
- 【opencv】opencv函数isContinuous
isContinuous 参考 1. opencv_isContinuous; 完
- python logging模块日志输出
import logging logger = logging.getLogger(__name__) logger.setLevel(level = logging.INFO) handler = ...
- poj3630||hdoj1671(字典树)
题目链接:https://vjudge.net/problem/HDU-1671 题意:给定n个字符串,判断是否存在一些字符串是另一些字符串的前缀. 思路: 套模板,存在前缀可能是两种情况: 当前字符 ...
- HTTP权威指南-报文与状态码
所有的报文都向下流动 报文流向 报文组成 HTTP方法 状态码 GET示例 HEAD示例 100~199 信息性状态码 200~299 成功状态码 300~399重定向状态码 400~499 客户端错 ...
- 20191104-基于Python计数排序算法分析
计数排序 计数排序算法没有用到元素间的比较,它利用元素的实际值来确定它们在输出数组中的位置,也就是说元素从未排序状态变为已排序状态的过程,是由额外空间的辅助和元素本身的值决定的,将每个元素出现的次数记 ...
- PAT甲级题分类汇编——计算
本文为PAT甲级分类汇编系列文章. 计算类,指以数学运算为主或为背景的题. 题号 标题 分数 大意 1058 A+B in Hogwarts 20 特殊进制加法 1059 Prime Factors ...
- C++ 数组和vector的基本操作
1.静态数组的基本操作 int a[5] = {0, 3, 4, 6, 2}; 1.1 数组的遍历 1.1.1 传统的for循环遍历 int size = sizeof(a) / sizeof(*a) ...
- show processlist说明
mysql> show processlist; 有时候输出太多,可以用下面的语句代替 mysql> select * from information_schema.processlis ...
- h5开发微信公众号重定向到关注页面没有关注按钮 (微信你个坑)
搜索微信公众号是这样的 微信公众号重定向到关注页面没有关注按钮 如何微信公众号重定向到关注页面没有关注按钮,请看上篇笔记 无解,微信一直在封这种通过链接跳转到公众号关注页面的方法.只有放个二维码提示长 ...
- 生成ftp文件的目录树
依赖 <dependency> <groupId>commons-net</groupId> <artifactId>commons-net</a ...