如何将视图放在确切的列和行中并使其填充该列 GridLayout android

How to put a view in exact column and row and make it fill that column GridLayout android

我在这里遇到一些关于网格布局的问题。 假设我有一个覆盖整个屏幕的网格布局,并且具有固定的行数和列数(例如 8/8)。现在假设我想插入 2 个自定义视图,它们只匹配它们插入的列和行。

图片示例:

如果图片不好,我很抱歉 :D 请记住,列的宽度和高度是固定在设备屏幕上的,视图不应该展开它,而是应该填充那 1 列。我确信有可能实现这一目标,但不幸的是,直到现在我还没有找到解决方案。非常感谢任何帮助,谢谢!!!!

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0099cc"
    tools:context="com.example.luka.gridlayouttest.FullscreenActivity"
    android:columnCount="12"
    android:rowCount="12"
    android:columnOrderPreserved="true"
    android:rowOrderPreserved="true">

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView5"
        android:layout_row="1"
        android:layout_column="3"/>

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView6"
        android:layout_row="4"
        android:layout_column="6" />
</GridLayout>

你做得对。你只是不完整。未定义的视图本质上具有零大小。如果你添加类似

android:text="row0, col0"
android:layout_row="0"
android:layout_column="0"/>

android:text="row1, col1"
android:layout_row="1"
android:layout_column="1"/>

等等,你会看到你的 TextViews 向右斜向下。似乎您必须填充网格中的每个视图才能为您提供完整的网格。对于每个视图,您要么必须给它一个固定的大小(而不是 wrap_content),要么用一些东西填充它(使用 android:text="row0, col0")。