【发布时间】:2015-05-27 05:26:15
【问题描述】:
我正在尝试制作类似于the example on the official Android Developers blog.的网格形式
这是我的布局:
<?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>
我的左栏(静态文本,右对齐)工作正常。它将文本向右对齐,宽度取决于最宽的行。
但是,右列似乎超出了 GridLayout 的范围。
在那张图片中,蓝色框是 GridLayout 的边界。您已经可以在顶部的绿色栏中看到问题。右侧应该停在 GridLayout 的边界处(就像左侧一样),但由于某种原因,它会超过它。
该图片中的蓝色框是 EditText 的边界(设置为 wrap_content)。但是,水色框是允许扩展的范围。当我在 EditText 中输入大量字符时,它超出了 GridLayout 的边界,甚至超出了手机屏幕的边缘!
这是 GridLayout 中的错误吗?还是我错过了什么?
【问题讨论】:
-
您找到解决方案了吗?
标签: android android-layout android-gridlayout