Android 4.0新组件:GridLayout详细说明
于Android 4.0(API 14)它提供了一个新的组件GridLayout,它继承自Linearlayout,用于执行网络格样式布局。
在某些方面,GridLayout与TableLayout和GridView有相似去处。于能够指定每个单元格“横跨”几个单元格或者“竖跨”几个单元格。这一点与html中<table>标签非常类似。
GridLayout的几个重要属性:
rowCount:行数
columnCount:列数
GridLayout的子View将能够应用属性:
layout_rowSpan:纵向跨几个单元格
layout_columnSpan:横向跨几个单元格
同一时候。GridLayout的子View能够不指定layout_width和layout_height(类似于TableLayout)
使用GridLayout能够非常方便的开发出类似计算器的页面。相比使用LinearLayout简化了代码、简化了嵌套层次、提高了性能,而且自适应性能更好。
示意图:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYm9va3MxOTU4/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" width="270" height="480" alt="">
布局代码:
<? xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="match_parent"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="计算器" /> <GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:rowCount="5"
android:columnCount="4"
android:layout_margin="4dp"> <Button android:text="C" /> <Button android:text="Del" /> <Button android:text="/" /> <Button android:text="x" /> <Button android:text="7" /> <Button android:text="8" /> <Button android:text="9" /> <Button android:text="-" /> <Button android:text="4" /> <Button android:text="5" /> <Button android:text="6" /> <Button android:text="+" /> <Button android:text="1" /> <Button android:text="2" /> <Button android:text="3" /> <Button
android:text="="
android:layout_gravity="fill"
android:layout_rowSpan="2" /> <Button
android:text="0"
android:layout_gravity="fill"
android:layout_columnSpan="2" /> <Button android:text="." /> </GridLayout>
</LinearLayout>
版权声明:本文博主原创文章。博客,未经同意不得转载。
Android 4.0新组件:GridLayout详细说明的更多相关文章
- android 5.0新特性
Android Lollipop 面向开发人员的主要功能 Material Design 设计 注重性能 通知 以大屏幕呈现 以文档为中心 连接性能再上一级 高性能图形 音频处理功能更强 摄像头和视频 ...
- android 7.0 新特性 和对开发者的影响
android 7.0新特性 - jiabailong的专栏 - 博客频道 - CSDN.NEThttp://blog.csdn.net/jiabailong/article/details/5241 ...
- Android 6.0 新特性 整理 资料来自网络
Android 6.0新特性 Runtime Permissions Doze and App Standby Apache HTTP Client Removal BoringSSL Access ...
- Android 5.0新控件——FloatingActionButton(悬浮按钮)
Android 5.0新控件--FloatingActionButton(悬浮按钮) FloatingActionButton是5.0以后的新控件,一个悬浮按钮,之所以叫做悬浮按钮,主要是因为自带阴影 ...
- Android 8.0 新特性
Android 8.0 (Android Oreo(奥利奥))新特性介绍 通知渠道 - Notification Channels 通知渠道是由应用自行定义的通知内容类别,借助渠道,开发者可以让用户对 ...
- Android Studio3.0 新特性 ~ New Features in Android Studio Preview (译文)
原文地址:https://developer.android.google.cn/studio/preview/features/index.html 最新Android Studio版本是Andro ...
- Android 6.0 新功能及主要 API 变更
运行时权限 这个版本中引入了新的权限模型,现在用户可以在运行时直接管理应用程序的权限.这个模型基于用户对权限控制的更多可见性,同时为应用程序的开发者提供更流畅的应用安装和自动升级.用户可以为已安装的每 ...
- Android 5.0 新特性
Material Design Material Design简介 Material Design是谷歌新的设计语言,谷歌希望寄由此来统一各种平台上的用户体验,Material Design的特点是干 ...
- Android 9.0新特性
1.全面屏支持,Android P加入了对刘海屏的支持,谷歌称之为凹口屏幕(display with a cutout).借助最新的提供的DisplayCutout类,开发者可以找到非功能区域的位置和 ...
随机推荐
- Android资源管理框架(Asset Manager)简介和学习计划
Android该应用程序包括两个部分组成的:代码和资源. 资源主要是与UI相关的东西,例如UI布局.和其他字符串和照片.代码和资源可以使独立的应用程序来组织的实际需求的基础上,在执行的时候UI.,就能 ...
- MySQL HINT:Straight_JOIN
来自生产环境的朋友.可能都会碰到: 原本运行良好的查询语句,过了一段时间后,可能会突然变得很糟糕 一个很大可能的原因就是数据分布情况发生了变化 从而导致MySQL优化 ...
- iframe动态创建及释放内存
近期參与一个项目的开发,因为项目是基于浏览器的胖client(RIA)应用程序,页面中大量调用iframe.后期測试发现浏览器内存一直居高不下,并且打开iframe页面越多内存占用越大.在IE系列浏览 ...
- C# openfiledialog设置filter属性后达不到过滤效果的原因之一
此处用RichTextBox控件举例>>> 在窗体对应的类中处理Load事件可以为openfiledialog设置Filter的属性: private void Form1_Load ...
- poj 1991 Turning in Homework dp
这个可以证明必须从两边的任务开始交起,因为中间交的任务可以后面经过的时候再交,所以就变成了一个n*n的dp. #include <iostream> #include <cstdio ...
- oschina Web应用开发
Web应用开发 SPDY开发包(13) HTML5开发相关(105) Pjax相关项目(4) 网站API(93) REST/RESTful项目(72) 响应式 Web 框架(27) 微信相关软件(63 ...
- cocos2D(四)---- CCSprite
在介绍CCSprite之前,先要理解游戏开发中的一个核心概念:精灵.精灵也称为游戏对象,它能够用来表示游戏中的不论什么物体,比方敌人.子弹.甚至是一个背景图片.一段文字.CCSprite能够说是在co ...
- F5 root密码恢复
使用串口线缆链接F5的串口和PC相连接,调节串口的波特率为12000,重启F5 后在启动菜单上和linux 单用户模式一样操作即可.
- poj1849(求树的直径)
题目链接:http://poj.org/problem?id=1849 题意:有一颗n个结点的带权的无向树, 在s结点放两个机器人, 这两个机器人会把树的每条边都走一遍, 但是最后机器人不要求回到出发 ...
- java获取当前日期时间代码总结
1.获取当前时间,和某个时间进行比较.此时主要拿long型的时间值. 方法如下: 要使用 java.util.Date .获取当前时间的代码如下 代码如下 复制代码 Date date = new ...