2月23日网格布局GridLayout

1.直接在里面写入按钮,默认横向显示
在这里插入图片描述

<?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:text="第1个"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
    <Button
        android:text="第2个"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
    <Button
        android:text="第3个"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
    <Button
        android:text="第4个"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
    <Button
        android:text="第5个"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
</GridLayout>

2.纵向显示
在这里插入图片描述

android:orientation="vertical"

3.设置行的显示个数
一行显示多少列
在这里插入图片描述

    android:columnCount="3"

4.设置列的显示个数
两行代码同时作用,表示一列显示多少行
在这里插入图片描述

    android:orientation="vertical"
    android:rowCount="3"

5.行列的三个属性

显示在第几列

横向跨几列

横向剩余空间分配方式

第二个按钮显示在1行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">

    <Button

        android:text="第1个"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
    <Button
        android:text="第2个"
        android:layout_row="1"
        android:layout_column="0"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
    <Button
        android:text="第3个"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
    <Button
        android:text="第4个"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
    <Button
        android:text="第5个"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
</GridLayout>

表示剩余空间由第五个按钮占用
在这里插入图片描述

    <Button
        android:text="第5个"
        android:layout_columnWeight="1"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />

横向剩余占用+纵向剩余占用
在这里插入图片描述

<?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:text="第1个"

        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
    <Button
        android:text="第2个"
        android:layout_row="1"
        android:layout_column="0"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
    <Button
        android:text="第3个"
        android:layout_row="0"
        android:layout_column="1"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
    <Button
        android:text="第4个"
        android:layout_columnWeight="1"     //这列上横向剩余占用
        android:layout_rowWeight="1"        //纵向剩余占用
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
    <Button
        android:text="第5个"

        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
</GridLayout>

6.第二个按钮横跨三列
在这里插入图片描述

    <Button
        android:text="第2个"
        android:layout_row="1"
        android:layout_column="0"
        android:layout_columnSpan="3"      //两行代码同时作用
        android:layout_gravity="fill"      //在网络中的显示位置
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值