我用一堆按钮创建了一个简单的GridLayout。每个按钮都有
layout_columnWeight
layout_rowWeight
设置为“1”可使gridlayout展开以填充空间。
任何
从左上角按钮,所有
其他
有人能解释一下这是怎么回事吗?
我的完整布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.gridlayout.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/colorAccent">
<Button
android:id="@+id/button24"
android:text="7"
app:layout_column="0"
app:layout_row="1"
app:layout_columnWeight=".01"
app:layout_rowWeight="1" />
<Button
android:id="@+id/button25"
android:text="8"
app:layout_column="1"
app:layout_row="1"
app:layout_columnWeight="1"
app:layout_rowWeight="1" />
<Button
android:id="@+id/button26"
android:text="9"
app:layout_column="2"
app:layout_row="1"
app:layout_columnWeight="1"
app:layout_rowWeight="1" />
<Button
android:id="@+id/button28"
android:text="4"
app:layout_column="0"
app:layout_row="2"
app:layout_columnWeight="1"
app:layout_rowWeight="1" />
<Button
android:id="@+id/button29"
android:text="5"
app:layout_column="1"
app:layout_row="2"
app:layout_columnWeight="1"
app:layout_rowWeight="1" />
<Button
android:id="@+id/button30"
android:text="6"
app:layout_column="2"
app:layout_row="2"
app:layout_columnWeight="1"
app:layout_rowWeight="1" />
<Button
android:id="@+id/button34"
android:text="1"
app:layout_column="0"
app:layout_row="3"
app:layout_columnWeight="1"
app:layout_rowWeight="1" />
<Button
android:id="@+id/button35"
android:text="2"
app:layout_column="1"
app:layout_row="3"
app:layout_columnWeight="1"
app:layout_rowWeight="1" />
<Button
android:id="@+id/button36"
android:text="3"
app:layout_column="2"
app:layout_row="3"
app:layout_columnWeight="1"
app:layout_rowWeight="1" />
</androidx.gridlayout.widget.GridLayout>
</LinearLayout>