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简化了代码、简化了嵌套层次、提高了性能,而且自适应性能更好。

示意图:

   

布局代码:

<?

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>



版权声明:本文博主原创文章。博客,未经同意不得转载。







本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/4910305.html,如需转载请自行联系原作者


相关文章
|
14天前
|
存储 设计模式 数据库
构建高效的安卓应用:探究Android Jetpack架构组件
【4月更文挑战第20天】 在移动开发的世界中,构建一个既高效又可维护的安卓应用是每个开发者追求的目标。随着Android Jetpack的推出,Google为开发者提供了一套高质量的库、工具和指南,以简化应用程序开发流程。本文将深入探讨Jetpack的核心组件之一——架构组件,并展示如何将其应用于实际项目中,以提升应用的响应性和稳定性。我们将通过分析这些组件的设计原则,以及它们如何协同工作,来揭示它们对于构建现代化安卓应用的重要性。
|
14天前
|
Android开发
Android四大组件详解2
Android四大组件详解
28 1
|
14天前
|
存储 监控 数据可视化
Android四大组件详解1
Android四大组件详解
45 0
|
14天前
|
设计模式 Android开发
[Android 四大组件] --- BroadcastReceiver
[Android 四大组件] --- BroadcastReceiver
37 0
|
12天前
|
Android开发 算法 架构师
android的基础ui组件,这些知识点你会吗
android的基础ui组件,这些知识点你会吗
android的基础ui组件,这些知识点你会吗
|
12天前
|
Android开发 缓存 双11
android的基础ui组件,Android开发社招面试经验
android的基础ui组件,Android开发社招面试经验
android的基础ui组件,Android开发社招面试经验
|
14天前
|
Java 开发工具 Android开发
如何在Eclipse中查看Android源码或者第三方组件包源码(转)
如何在Eclipse中查看Android源码或者第三方组件包源码(转)
18 4
|
11天前
|
存储 设计模式 监控
88 PM撸代码之【Android四大基本组件】
88 PM撸代码之【Android四大基本组件】
16 0
|
11天前
|
前端开发 Android开发
Android架构组件JetPack之DataBinding玩转MVVM开发实战(四)
Android架构组件JetPack之DataBinding玩转MVVM开发实战(四)
Android架构组件JetPack之DataBinding玩转MVVM开发实战(四)
|
14天前
|
设计模式 前端开发 数据库
构建高效Android应用:使用Jetpack架构组件实现MVVM模式
【4月更文挑战第21天】 在移动开发领域,构建一个既健壮又易于维护的Android应用是每个开发者的目标。随着项目复杂度的增加,传统的MVP或MVC架构往往难以应对快速变化的市场需求和复杂的业务逻辑。本文将探讨如何利用Android Jetpack中的架构组件来实施MVVM(Model-View-ViewModel)设计模式,旨在提供一个更加模块化、可测试且易于管理的代码结构。通过具体案例分析,我们将展示如何使用LiveData, ViewModel, 和Repository来实现界面与业务逻辑的分离,以及如何利用Room数据库进行持久化存储。最终,你将获得一个响应迅速、可扩展且符合现代软件工
31 0