【发布时间】:2020-09-17 04:43:33
【问题描述】:
当我添加第 5 列时,带有数字 5 一半的按钮爬出屏幕。当我为按钮添加值:android:layout_columnWeight="1" 时,编号为 1 的按钮会伸出屏幕。
如何在屏幕上显示所有 5 列?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:rowCount="5"
android:columnCount="5">
<Button
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="1"
android:textSize="25dp"
android:textColor="@color/white"
android:background="@color/black"
android:layout_row="0"
android:layout_column="0"/>
<Button
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="2"
android:textSize="25dp"
android:textColor="@color/white"
android:background="@color/black"
android:layout_row="0"
android:layout_column="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="3"
android:textSize="25dp"
android:textColor="@color/white"
android:background="@color/black"
android:layout_row="0"
android:layout_column="2"/>
<Button
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="4"
android:textSize="25dp"
android:textColor="@color/white"
android:background="@color/black"
android:layout_row="0"
android:layout_column="3"/>
<Button
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="5"
android:textSize="25dp"
android:textColor="@color/white"
android:background="@color/black"
android:layout_row="0"
android:layout_column="4"/>
</GridLayout>
</RelativeLayout>
【问题讨论】:
-
你能在 Llinearlayout 中试试这个,然后它会在屏幕中正确显示。如果它只是一个按钮
-
减少
android:textSize。 GridLayout 强制? -
它就像计算器键。
标签: android xml grid-layout android-gridlayout