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中,其实方法就是函数,只不过叫法不同,在 ...
随机推荐
- Fragment already added问题的解决
问题 当快速点击切换不同的Fragment的时候部分手机的app竟然挂了,报出了下面的错误 Fragment already added java.lang.IllegalStateExcepti ...
- Laya的动画制作,整图动画,序列图动画,时间轴动画,龙骨动画
参考: Laya动画基础 Egret帧动画工具类 版本:2.1.1.1 序列图动画 白鹭的序列图动画,使用TexureMerger合图,然后使用MovieClip类播放. Laya的话,使用图集打包工 ...
- [转载]SQL Server提权系列
本文原文地址:https://www.cnblogs.com/wintrysec/p/10875232.html 一.利用xp_cmdshell提权 xp_cmdshell默认是关闭的,可以通过下面的 ...
- Mybatis笔记2
使用Mybatis完成的CRUD操作 个人总结的一些小规律 学习过程中碰到的错误: org.apache.ibatis.exceptions.PersistenceException: ### Err ...
- Python32之类和对象2(self参数及魔法方法)
一.类方法中的self参数含义 在Python中类的方法都要有self参数,其实质为对类的实例化对象的绑定从而使得在类的实例化对象调用方法时能够确认出是对哪个对象进行操作. 带self的的参数是人家实 ...
- C++ 中 static 与 const 的用法及对比
在这个学习过程中我对 static 及 const 的使用时常会混淆,因此整理,加深记忆 一.类的静态成员 如果某个属性为整个类所共有,不属于任何一个具体对象,则采用 static 关键字来声明静态成 ...
- 100天搞定机器学习|day54 聚类系列:层次聚类原理及案例
几张GIF理解K-均值聚类原理 k均值聚类数学推导与python实现 前文说了k均值聚类,他是基于中心的聚类方法,通过迭代将样本分到k个类中,使每个样本与其所属类的中心或均值最近. 今天我们看一下无监 ...
- 小白入门.有函数F(x)=(x+1)^2和G(x)=2x+1.输入x值计算F(G(x))。
#include<stdio.h> #include<math.h> void main() { float x,y; printf("Please input x\ ...
- linux根文件系统的挂载过程详解
一:前言 前段时间在编译kernel的时候发现rootfs挂载不上.相同的root选项设置旧版的image却可以.为了彻底解决这个问题.研究了一下rootfs的挂载过程.特总结如下,希望能给这部份知识 ...
- 在论坛中出现的比较难的sql问题:21(递归问题 检索某个节点下所有叶子节点)
原文:在论坛中出现的比较难的sql问题:21(递归问题 检索某个节点下所有叶子节点) 最近,在论坛中,遇到了不少比较难的sql问题,虽然自己都能解决,但发现过几天后,就记不起来了,也忘记解决的方法了. ...