Android学习笔记十七之GridLayout网格布局
来源:互联网 发布:传智播客168 erp 源码 编辑:程序博客网 时间:2024/05/24 04:31
Android学习笔记十七之GridLayout网格布局
GridLayout网格布局是Android系统API在4.0以后推出的一个新的布局方式,GridLayout布局使用虚细线将布局划分为行、列和单元格,也支持一个控件在行、列上都有交错排列。与LinearLayout布局一样,也分为水平和垂直两种方式,默认是水平布局,一个控件挨着一个控件从左到右依次排列,但是通过指定android:columnCount设置列数的属性后,控件会自动换行进行排列。
在GridLayout网格布局中可以自己设置布局中组件的排列方式,可以自定义网格布局的行数、列数,可以直接设置组件位于某行某列,可以设置组件横跨几行或者几列。
注意:如果需要兼容4.0之前的版本,就需要使用v7包中的GridLayout。
下面通过实现一个计算器布局说明一下GridLayout的用法:
布局代码:
<?xml version="1.0" encoding="utf-8"?><GridLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_marginTop="16dp"android:columnCount="4"android:orientation="horizontal"android:rowCount="6"><TextView android:id="@+id/tv_show" android:layout_columnSpan="4" android:layout_gravity="fill" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_marginTop="8dp" android:background="#EEEEE0" android:paddingLeft="8dp" android:text="0" android:textSize="50sp" /><Button android:id="@+id/btn_back" android:text="返回" /><Button android:id="@+id/btn_del" android:text="清空" /><Button android:id="@+id/btn_divide" android:text="/" /><Button android:id="@+id/btn_ride" android:text="X" /><Button android:id="@+id/btn_cal_7" android:text="7" /><Button android:id="@+id/btn_cal_8" android:text="8" /><Button android:id="@+id/btn_cal_9" android:text="9" /><Button android:id="@+id/btn_reduce" android:text="-" /><Button android:id="@+id/btn_cal_4" android:text="4" /><Button android:id="@+id/btn_cal_5" android:text="5" /><Button android:id="@+id/btn_cal_6" android:text="6" /><Button android:id="@+id/btn_plus" android:text="+" /><Button android:id="@+id/btn_cal_1" android:text="1" /><Button android:id="@+id/btn_cal_2" android:text="2" /><Button android:id="@+id/btn_cal_3" android:text="3" /><Button android:id="@+id/btn_spot" android:text="." /><Button android:id="@+id/btn_cal_0" android:layout_columnSpan="2" android:layout_gravity="fill" android:text="0" /><Button android:id="@+id/btn_equal" android:layout_columnSpan="2" android:layout_gravity="fill" android:text="=" /></GridLayout>
效果图:
这里只是画出界面,并没有完成计算器,有兴趣的同学可以完成具体的计算器。其中,android:layout_columnSpan这个属性是指横跨多少列,android:layout_rowSpan属性是指需要横跨多上行,比如我设置android:layout_columnSpan=”2”,就是横跨2列,android:layout_rowSpan=”2”就是横跨2行。关于GridLayout网格布局就介绍到这里,照例附上GridLayout网格布局的国内镜像API。下面我们介绍AbsoluteLayout绝对布局
0 0
- Android学习笔记十七之GridLayout网格布局
- Android学习笔记十七之GridLayout网格布局
- Android学习笔记(15):网格布局GridLayout
- android之网格布局GridLayout
- android布局学习:GridLayout 网格布局
- Android UI之GridLayout(网格布局)
- Android学习 9-> 表格布局TableLayout和网格布局GridLayout
- (五)Android布局之网格布局(GridLayout)
- swing 学习笔记十二(网格布局GridLayout)
- Android布局——GridLayout(网格布局)
- 我的笔记 网格布局 GridLayout
- 十八、java-GUI之网格布局(GridLayout)
- android 简单的网格布局 GridLayout
- Android开发——GridLayout网格布局
- Android--(9)--详解网格布局(GridLayout)
- Android GridLayOut布局学习
- Android 布局之GridLayout
- Android 布局之GridLayout
- swiper的基本使用(十三)
- LeetCode - 88. Merge Sorted Array
- TCP/IP 机制的理解
- 控制范围
- 浅谈Linux的I/O模型
- Android学习笔记十七之GridLayout网格布局
- GIPS-NetEQ 最大化话音质量、最小化延迟
- 关于Windows下使用Wamp搭建服务器出现403错误问题解决办法
- Android Material Design 详解(使用support v7兼容5.0以下系统)
- 玩具装箱[HNOI 2008][Codevs 1319]
- 自定义View重绘使requestLayout, invalidate和postInvalidate的异同
- CentOS7.1 VNC Server服务配置
- Java连接池详细总结
- Android学习笔记:EditText InputTye汇总