Android布局【GridLayout】

GridLayout概述

GridLayout也名网格布局,该布局与TableLayout类似,但与其相比,GridLayout会更加的灵活,比如

TableLayout不能将两行进行一个合并,只能将两列进行一个合并;而GridLayout既能合并行也能合并列,而且布局也会更加的灵活

常见属性

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

子控件属性

  1. android:layout_column显示在第几列
  2. android:layout_columnSpan:横向跨几列
  3. android:layout_columnWeight:横向剩余空间分配方式
  4. android:layout_gravity:在网格中的显示位置
  5. android:layout_row:显示在第几行
  6. android:layout_rowSpan:纵向跨几行
  7. android:layout_rowWeight:纵向剩余空间分配方式

项目结构

在这里插入图片描述

主要代码

activity_main.xml

<?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">

    <Button
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="按钮0"/>

    <Button
        android:layout_gravity="center"
        android:layout_columnSpan="2"
        android:layout_row="1"
        android:layout_column="0"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="按钮1"/>

    <Button
        android:layout_rowSpan="1"
        android:layout_rowWeight="2"
        android:layout_columnWeight="1"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="按钮2"/>

    <Button
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="按钮3"/>

    <Button
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="按钮4"/>


</GridLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值