6

我在定位布局元素时遇到问题。我的 TableLayout 中的 AutoComplete 和它之后的按钮正在扩展 TableRow 大于屏幕的宽度。有人知道为什么吗?下面是我的 XML 代码以及问题的图片。

提前致谢!!

<?xml version="1.0" encoding="utf-8"?>

<TableRow android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <AutoCompleteTextView android:id="@+id/installation"
        android:textSize="14sp" android:completionThreshold="3" />
</TableRow>
<TableRow android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <Button android:id="@+id/btn_find" android:text="@string/btn_find"></Button>
</TableRow>
<TableRow android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TextView android:id="@+id/error" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:paddingTop="20px"
        android:textColor="#FF0000" />
</TableRow>

用户界面图片

4

2 回答 2

39

对于确实需要表格布局的人,请使用 layout_weight 选项。请参阅下面的代码。

        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="6sp" android:id="@+id/detailsLayout">
            <TableRow
                android:layout_width="wrap_content"
                android:id="@+id/TableRow03"
                android:layout_height="wrap_content">
                <TextView
                    android:id="@+id/TextView06"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:text="Detail 1"></TextView>
                <TextView
                    android:text="@string/empty_value"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:id="@+id/sessionAudience"
                    android:layout_weight="1"></TextView>
            </TableRow>
         </TableLayout>
于 2011-06-18T12:43:45.770 回答
5

默认情况下,a 中的小部件TableRow具有android:layout_width="wrap_content". 这并不限制您对屏幕的大小 -wrap_content意思是“包装内容”,而不是“包装内容,但如果您不介意,请不要离开屏幕边缘”。

在这种情况下,您不需要使用 aTableLayout和 set of TableRows,因为您没有表格。

因此,一种方法是使用 aRelativeLayout并让您AutoCompleteTextView使用android:layout_alignParentLeft="true"and android:layout_alignParentRight="true"。这会将其固定到 的外边缘RelativeLayout,您可以使用它来调整大小android:layout_width=fill_parent以填充屏幕。

于 2010-06-01T21:01:02.010 回答