Android学习|布局——GridLayout 表格布局_(可行、列合并)

Android学习|布局——GridLayout 表格布局一、GridLayout 行、列 都可以进行合并二、常见属性三、子控件属性四、Demo1、常见属性Demo一、GridLayout 行、列 都可以进行合并TableLayout只能设置其占据几列(列合并),而不能进行行的合并,要进行行的合并,可使用GridLayout布局。二、常见属性1、android:orientation : 设置水平显示还是垂直显示2、android:columnCount : 设置行的显示个数3、an
摘要由CSDN通过智能技术生成

一、GridLayout 行、列 都可以进行合并

TableLayout只能设置其占据几列(列合并),而不能进行行的合并,要进行行的合并,可使用GridLayout布局。

二、常见属性

1、android:orientation : 设置水平显示还是垂直显示
2、android:columnCount : 设置行的显示个数
3、android:rowCount : 设置列的显示个数

一般:设置 columnCount 时,设置orientation 为水平显示 horizontal
            设置 rowCount 数时,设置orientation 为垂直显示 vertical


三、子控件属性

1、android:layout_row:显示在第几行
2、android:layout_column:显示在第几列

3、android:layout_rowSpan:横向跨几行
4、android:layout_columnSpan:横向跨几列

5、android:layout_rowWeight :纵向乘剩余空间分配方式
6、android:layout_columnWeight:横向剩余空间分配方式

7、android:layout_gravity:在网格中的显示位置

layout_rowSpan、layout_columnSpan设置后,不会有明显作用,还需要设置layout_gravity才能起作用。



四、Demo

1、常见属性Demo

GridLayout设置如下属性:

android:orientation=“horizontal”
android:columnCount=“3”

则表格每行3列、水平显示

<?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:orientation="horizontal"
    android:columnCount="3">
    
    <Button
        android:text="1"/>

    <Button
        android:text="2"/>

    <Button
        android:text="3"/>

    <Button
        android:text="4"/>

    <Button
        android:text="5"/>


</GridLayout>

请添加图片描述

2、子控件属性Demo

a、layout_row、layout_column

1-5五个button中
2设置 在第1行第0列 (从0开始) (android:layout_row=“1”、android:layout_column=“0”)
5设置 在第2行第0列 (从0开始) (android:layout_row=“2”、android:layout_column=“0”)

<?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:orientation="horizontal">

    <Button
        android:
  • 5
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值