十四、GridLayout 網格佈局
阿新 • • 發佈:2022-03-28
一、常見屬性
android:orientation 設定水平顯示還是垂直顯示
android:columnCount 設定行的顯示個數
android:rowCount 設定列的顯示個數
二、子控制元件屬性
android:layout_column 顯示在第幾列
android:layout_columnSpan 橫向跨n列
android:layout_columnWeight 橫向剩餘空間分配方式
android:layout_gravity在網格中的顯示位置
android:layout_row 顯示在第幾行
android:layout_rowSpan 橫向跨幾行
android:layout_rowWeight 縱向剩餘空間分配方式
三、程式碼示例
<?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_row="0" 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:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_row="1" android:layout_column="0" android:text="第3個" /> <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"/> <Button android:text="第6個" android:layout_height="wrap_content" android:layout_width="wrap_content"/> </GridLayout>
四、效果圖