于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详细说明的更多相关文章

  1. android 5.0新特性

    Android Lollipop 面向开发人员的主要功能 Material Design 设计 注重性能 通知 以大屏幕呈现 以文档为中心 连接性能再上一级 高性能图形 音频处理功能更强 摄像头和视频 ...

  2. android 7.0 新特性 和对开发者的影响

    android 7.0新特性 - jiabailong的专栏 - 博客频道 - CSDN.NEThttp://blog.csdn.net/jiabailong/article/details/5241 ...

  3. Android 6.0 新特性 整理 资料来自网络

    Android 6.0新特性 Runtime Permissions Doze and App Standby Apache HTTP Client Removal BoringSSL Access ...

  4. Android 5.0新控件——FloatingActionButton(悬浮按钮)

    Android 5.0新控件--FloatingActionButton(悬浮按钮) FloatingActionButton是5.0以后的新控件,一个悬浮按钮,之所以叫做悬浮按钮,主要是因为自带阴影 ...

  5. Android 8.0 新特性

    Android 8.0 (Android Oreo(奥利奥))新特性介绍 通知渠道 - Notification Channels 通知渠道是由应用自行定义的通知内容类别,借助渠道,开发者可以让用户对 ...

  6. Android Studio3.0 新特性 ~ New Features in Android Studio Preview (译文)

    原文地址:https://developer.android.google.cn/studio/preview/features/index.html 最新Android Studio版本是Andro ...

  7. Android 6.0 新功能及主要 API 变更

    运行时权限 这个版本中引入了新的权限模型,现在用户可以在运行时直接管理应用程序的权限.这个模型基于用户对权限控制的更多可见性,同时为应用程序的开发者提供更流畅的应用安装和自动升级.用户可以为已安装的每 ...

  8. Android 5.0 新特性

    Material Design Material Design简介 Material Design是谷歌新的设计语言,谷歌希望寄由此来统一各种平台上的用户体验,Material Design的特点是干 ...

  9. Android 9.0新特性

    1.全面屏支持,Android P加入了对刘海屏的支持,谷歌称之为凹口屏幕(display with a cutout).借助最新的提供的DisplayCutout类,开发者可以找到非功能区域的位置和 ...

随机推荐

  1. W​i​n​D​B​G​调​试​技​巧

    参考链接:http://wenku.baidu.com/view/4e58744dcf84b9d528ea7a42.html

  2. NET Core 中的依赖注入

    NET Core 中的依赖注入 [共7篇] 一.控制反转(IoC) ASP.NET Core在启动以及后续针对每个请求的处理过程中的各个环节都需要相应的组件提供相应的服务,为了方便对这些组件进行定制, ...

  3. cocos2d-x项目101次相遇: Scenes , Director, Layers, Sprites

    cocos2d-x 101次相遇 / 文件夹  1   安装和环境搭建 -xcode  2   Scenes , Director, Layers, Sprites 3   建立图片菜单  4   在 ...

  4. JavaScript(15)jQuery 选择器

    jQuery 选择器 选择器同意对元素组或单个元素进行操作. jQuery 元素选择器和属性选择器同意通过标签名.属性名或内容对 HTML 元素进行选择. 在 HTML DOM 术语中:选择器同意对 ...

  5. c4Droid

    c4可以让用c/c++写的源码打包成apk安装包,支持Console.SDL.Qt. NativeActivity 等一系列扩展库,可以用来写软件,也可以用来写游戏,是手机端练习c/c++的神器.c4 ...

  6. hdu4035(概率dp)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4035 题意:有n个房间,由n-1条隧道连通起来,实际上就形成了一棵树, 从结点1出发,开始走,在每个结 ...

  7. 每日算法之三十八:Anagrams

    Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...

  8. 逆向 Framework.jar

    Ref:http://www.addictivetips.com/mobile/what-is-odex-and-deodex-in-android-complete-guide/ Ref:http: ...

  9. JS兼容的方式来获取浏览器的宽度

    <script type="text/javascript"> //need to wait until onload so body is available win ...

  10. IntelliJ IDEA Groovy(转)

    更新环境变量: source /etc/profile 验证是否成功: # groovy -version Groovy Version: 2.3.6 JVM: 1.7.0_67 Vendor: Or ...