相关疑难解决方法(0)

GridLayout列超出了它的范围

我正在尝试制作类似网格的形式,类似于官方Android开发者博客上的示例.

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="48dp"
        android:layout_marginRight="48dp"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:columnCount="2"
        android:rowCount="2">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="0"
            android:layout_gravity="end"
            android:layout_row="0"
            android:text="Send"
            android:textColor="?android:attr/textColorPrimary"
            android:textSize="24sp" />

        <Spinner
            android:id="@+id/send_currency"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_row="0" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="0"
            android:layout_gravity="end"
            android:layout_row="1"
            android:text="to"
            android:textColor="?android:attr/textColorPrimary"
            android:textSize="24sp" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_row="1"
            android:hint="username"
            android:textColor="?android:attr/textColorPrimary"
            android:textSize="24sp" />
    </GridLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我的左栏(静态文本,右对齐)工作正常.它将文本对齐,宽度取决于最宽的行.

但是,右列似乎是在GridLayout范围之外绘制的.

选择了GridLayout的布局预览

在该图片中,蓝色框是GridLayout的边界.您已经可以在顶部的绿色栏中看到问题.右侧应该停在GridLayout的边界(就像左侧一样),但由于某种原因它会超越它.

选择了右列的布局预览

该图片中的蓝色框是EditText的边界(它设置为wrap_content).然而,浅绿色的盒子是允许它扩展的范围.当我在EditText中输入大量字符时,它会经过GridLayout的边界,甚至超过手机屏幕的边缘!

截图

这是GridLayout中的错误吗?或者我错过了什么?

android android-layout android-gridlayout

8
推荐指数
2
解决办法
3596
查看次数