Ich versuche, ein GridLayout von 8x8 Tasten (wie ein Minesweeper) zu machen. Ich verwalte die Gewichte für alle die gleiche Breite, aber es funktioniert gut bis 4 Tasten. Wenn ich die fünfte Schaltfläche in Spalte 4 hinzufüge, erweitern sie die Breite im Vollbildmodus. Das ist mein xml:Gridlayout von Tasten größer als 4 Spalten
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/GridLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:columnCount="8"
android:orientation="horizontal"
android:rowCount="8"
tools:context=".MainActivity">
<Button
android:id="@+id/b1"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_row="0"
android:text="B" />
<Button
android:id="@+id/b2"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_row="0"
android:text="B" />
<Button
android:id="@+id/b3"
android:layout_column="2"
android:layout_columnWeight="1"
android:layout_row="0"
android:text="B" />
<Button
android:id="@+id/b4"
android:layout_column="3"
android:layout_columnWeight="1"
android:layout_row="0"
android:text="B" />
</GridLayout>
Entwurf mit 4-Taste: 4 button
Als ich die fünfte Taste, um die 4-Säule hinzu: button expands
Vielen Dank!
gehen Sie zu diesem Link, der Ihrem Problem ähnelt https://StackOverflow.com/Questions/10016343/Gridlayout-Not-Gridview-how-to-stretch-all-Children-Evenly –