网格布局

GridLayout(网格布局)

特点:

1、可以自己设置布局中组件的排列方式

2、可以自定义网格布局有多少行,多少列

3、可以直接设置组件位于某行某列

4、可以设置组件横跨几行或者几列

关键的两个属性:

android:rowCount 设置行的个数

android:columnCount 设置列的个数

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:rowCount="4"
    android:columnCount="4">

    <TextView
        android:layout_height="50dp"
        android:layout_columnWeight="1"
        android:background="#0f0"></TextView>

    <TextView
        android:layout_height="50dp"
        android:layout_columnWeight="1"
        android:background="#f0f"></TextView>

    <TextView
        android:layout_height="50dp"
        android:layout_columnWeight="1"
        android:background="#ff0"></TextView>

    <TextView
        android:layout_height="50dp"
        android:layout_columnWeight="1"
        android:background=""></TextView>

    <TextView
        android:layout_height="50dp"
        android:layout_columnWeight="1"
        android:background="#ff0"></TextView>

    <TextView
        android:layout_height="50dp"
        android:layout_columnWeight="1"
        android:background="#00f"></TextView>

    <TextView
        android:layout_height="50dp"
        android:layout_columnWeight="1"
        android:background="#0f0"></TextView>

</GridLayout>

效果如下:一共被分为8个

posted @ 2020-03-10 20:06  zpchcbd  阅读(292)  评论(0)    收藏  举报