Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:在GridLayout中添加列会破坏网格,使第一列溢出_Android_Grid Layout - Fatal编程技术网

Android:在GridLayout中添加列会破坏网格,使第一列溢出

Android:在GridLayout中添加列会破坏网格,使第一列溢出,android,grid-layout,Android,Grid Layout,我正在尝试使用gridlayout来创建一个5x5网格的等距按钮。该行的前四列显示得很好,完全符合我的要求(当我测试新行时,新行似乎也开始运行得很好) 以下是相关的xml: <androidx.gridlayout.widget.GridLayout android:id="@+id/gridLayoutBoard" android:layout_width="0dp" android:layout_height="0dp"

我正在尝试使用gridlayout来创建一个5x5网格的等距按钮。该行的前四列显示得很好,完全符合我的要求(当我测试新行时,新行似乎也开始运行得很好)

以下是相关的xml:

    <androidx.gridlayout.widget.GridLayout
        android:id="@+id/gridLayoutBoard"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:columnCount="5"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:rowCount="5">

        <Button
            android:id="@+id/buttonBoardCell00"
            android:onClick="buttonBoardCellOnClick"
            app:layout_column="0"
            app:layout_columnWeight="1"
            app:layout_row="0"
            app:layout_rowWeight="1" />
        <Button
            android:id="@+id/buttonBoardCell01"
            android:onClick="buttonBoardCellOnClick"
            app:layout_column="1"
            app:layout_columnWeight="1"
            app:layout_row="0"
            app:layout_rowWeight="1" />
        <Button
            android:id="@+id/buttonBoardCell02"
            android:onClick="buttonBoardCellOnClick"
            app:layout_column="2"
            app:layout_columnWeight="1"
            app:layout_row="0"
            app:layout_rowWeight="1" />
        <Button
            android:id="@+id/buttonBoardCell03"
            android:onClick="buttonBoardCellOnClick"
            app:layout_column="3"
            app:layout_columnWeight="1"
            app:layout_row="0"
            app:layout_rowWeight="1" />



    </androidx.gridlayout.widget.GridLayout>
更改后,第一个单元格溢出,这是仿真器中的情况:

在Android Studio中:


我做错了什么?如何解决此问题?

在您的
按钮中添加
版面宽度
版面高度
0dp

<Button
    ...
    android:layout_width="0dp"
    android:layout_height="0dp"
    .../>

完成。我不得不等5分钟才被允许。
<Button
    ...
    android:layout_width="0dp"
    android:layout_height="0dp"
    .../>