android - 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 的按钮网格
解决方案
TextView 的宽度match_parent
将其更改为wrap_content
它将起作用并显示您或更改您的GridLayout
方向LinearLayout
vertical
推荐阅读
- sql - 在学生成绩列表中返回平均值的 Oracle 程序
- cucumber - 如何在 Gherkin 中的操作之前做出断言?
- excel - Excel 中的公式错误 - 未返回所需值
- php - 包含 PHP 的语句不要访问 .htaccess
- javascript - 如果没有引用对象,则使对象返回特定属性
- r - R:一个“整洁”的函数版本比原来的要慢得多,我想知道为什么
- c# - 使用导航网格时,敌人的移动仅在范围内跟随玩家
- javascript - 如何在核心 JavaScript 中格式化/美化 HTML、CSS 和 JavaScript 代码?
- r - 如何在 R 的 pheatmap 中插入多条垂直和水平线?
- reactjs - 持久存储不适用于 user_id 但适用于 access_token