Android:tablerow与列和多行文本混合

5
我正在尝试创建一个包含多个表格行的表格布局。其中一行包含4个按钮,而第二行包含非常长的文本。但是,按钮的宽度会随着第二行文本的长度而伸展。有什么办法可以防止这种情况发生吗?

alt text alt text

http://img684.imageshack.us/i/tableview1.jpg/

http://img521.imageshack.us/i/tableview2.jpg/

这是我的XML文件:(不知何故,该网站不友好地处理XML文件)
AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>

TableLayout
android:id="@+id/widget28"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_x="0px"
android:layout_y="10px"
>

TableRow
android:id="@+id/widget29"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>

Button
android:id="@+id/widget30"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
>
</Button>

Button
android:id="@+id/widget31"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
>
</Button>

Button
android:id="@+id/widget32"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
>
</Button>

Button
android:id="@+id/widget33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
>
</Button>
</TableRow>

TableRow
android:id="@+id/widget35"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>

TextView
android:id="@+id/widget40"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextViewTextViewTextViewTextViewTextViewTextView"
>
</TextView>
</TableRow>

</TableLayout>
</AbsoluteLayout>

也尝试在代码中设置属性,但没有成功。这是安卓的一个bug吗? - Yang
1个回答

3

尝试使用android:layout_span="4"来设置TextView的宽度

将4替换为第一行列数(按钮数)的实际数量。

此外,您可以在Tablerow中省略android:layout_width和layout_height参数。


没成功。文本超出了屏幕,第一个按钮仍然那么大。我开始怀疑这是 Android 的 Bug? - Yang
这对我有效,这是我这边的工作XML文件(可能您将layout_span属性放错了位置): <TableRow android:id="@+id/widget35" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/widget40" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_span="4" android:text="TextViewTextViewTextViewTextViewTextView" /></TableRow>此外,您可以轻松省略Button和其他tablerow标记中的layout_width =“wrap_content”layout_height =“wrap_content”。 - Anshul
此外,为什么要使用绝对布局呢?除非绝对必要,我不建议使用它。 - Anshul
谢谢...但是对我来说还是不起作用。我已经放弃了,使用了一个单独的Linearlayout来放置这些按钮。 - Yang

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接