當android api < 21,它不工作。
因此,更多地使用它來適應Android版本。
所以我們可以添加編譯。
compile 'com.android.support:gridlayout-v7:25.3.1'
和樣本。
<android.support.v7.widget.GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/GridLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f11"
app:columnCount="2"
app:rowCount="2">
<Button
android:id="@+id/button1"
android:text="Button"
app:layout_column="0"
app:layout_columnWeight="1"
app:layout_gravity="fill"
app:layout_row="0"
app:layout_rowWeight="1"/>
<Button
android:id="@+id/button2"
android:text="Button"
app:layout_column="1"
app:layout_columnWeight="1"
app:layout_gravity="fill"
app:layout_row="0"
app:layout_rowWeight="1"/>
<Button
android:id="@+id/button3"
android:text="Button"
app:layout_column="0"
app:layout_columnWeight="1"
app:layout_gravity="fill"
app:layout_row="1"
app:layout_rowWeight="1"/>
<Button
android:id="@+id/button4"
android:text="Button"
app:layout_column="1"
app:layout_columnWeight="1"
app:layout_gravity="fill"
app:layout_row="1"
app:layout_rowWeight="1"/>
</android.support.v7.widget.GridLayout>
注意
在com.android.support:gridlayout-v7:25.3.1
25.3.1
改變你自己。
它有新的屬性。
- 應用:layout_columnWeight
- 應用:layout_rowWeight
- 應用:layout_rowSpan
- 應用:layout_columnSpan
您可以在代碼中使用。
請查看https://developer.android.com/topic/libraries/support-library/index.html –
謝謝。該鏈接的信息很有幫助。然而,這是相當一般的信息,並沒有回答我關於GridLayout的問題。 – Barzee