Android——網格佈局管理器(GridLayout)

網格佈局管理器

在這裏插入圖片描述

在佈局管理器上所設置的屬性

android:columnCount最大幾列
android:orientation排布方式
android:rowCount最大幾行

android:columnCount="2"
android:rowCount="2"

在佈局管理器的組件上所設置的屬性

GridLayout.LayoutParams

android:layout_column列位置
android:layout_columnSpan列橫跨
android:layout_columnWeight列權重
android:layout_gravity
android:layout_ row
android:layout_rowSpan
android:layout_rowWeight

android:layout_row="0"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_columnSpan="2"
android:layout_gravity="fill"

樣例

在這裏插入圖片描述

<?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_width="wrap_content"
    android:layout_height="wrap_content"
        android:layout_row="0"
        android:layout_column="0"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:background="#7841"
    android:text="按鈕1"
    />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="0"
        android:layout_column="1"
        android:text="按鈕2"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:background="#856485"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="1"
        android:layout_column="0"
        android:background="#8621"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"

        android:text="按鈕3"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:background="#842365"
        android:text="按鈕4"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="2"
        android:layout_column="0"
        android:layout_rowWeight="1"
        android:layout_columnSpan="2"
        android:text="按鈕5"
        android:background="#985621"
        android:layout_gravity="fill"
        />
</GridLayout>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章