首页 > 解决方案 > GridLayout 不显示

问题描述

LinearLayout 中的 GridLayout 根本没有显示,也不知道为什么。试图制作一个简单的计算器,但我无法显示按钮。

更改了高度、宽度背景颜色,但不确定为什么不显示。

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="horizontal"
>

<TextView
    android:id="@+id/main_display"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="123456789"
    android:gravity="end"

    android:background="@color/mainDisplay" />

<GridLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:columnCount="4"
        android:rowCount="5"
        >
        <Button
         android:id="@+id/bc"
            android:text="@string/bc"

            />
        <Button
            android:id="@+id/bparentesis"
            android:text="@string/bparentesis"
            />

        <Button
            android:id="@+id/b7"
            android:text="@string/b7"
            />
        <Button
            android:id="@+id/b8"
            android:text="@string/b8"
            />
        <Button
            android:id="@+id/b9"
            android:text="@string/b9"
            />
        <Button
            android:id="@+id/bmulti"
            android:text="@string/bmulti"
            />
        <Button
            android:id="@+id/b4"
            android:text="@string/b4"
            />

    </GridLayout>

我试图为计算器制作一个 4x5 的按钮网格

标签: androidxml

解决方案


TextView 的宽度match_parent将其更改为wrap_content它将起作用并显示您或更改您的GridLayout方向LinearLayoutvertical


推荐阅读