我一直在尝试将表格行中的单元格排列在下面,以便第二个单元格的值(带有背景图像的按钮)正好位于第一个单元格文本的右侧。下图当前拉伸了单元格2中的图像,如下所示

。
关于如何停止拉伸并将按钮图像定位在单元格2的最左边,您有什么想法吗?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
<TableRow>
<TextView
android:id="@+id/timeMainLabel"
android:layout_weight="1"
android:textSize="14sp"
android:layout_column="0"
android:padding="1dip"
android:text="cell one texxxxxxxxt"/>
<Button
android:id="@+id/pdm_tooltip_btn1"
android:layout_column="1"
android:background="@drawable/tooltip_btn" />
<TextView
android:layout_column="2"
android:id="@+id/timeLabel"
android:textSize="14sp"
android:text="cell 3"
android:gravity="right"
android:padding="1dip"
android:visibility="visible"
android:layout_weight="1"/>
</TableRow>
<TableRow>
<TextView
android:id="@+id/timeMainLabel"
android:layout_weight="1"
android:textSize="14sp"
android:layout_column="0"
android:padding="1dip"
android:text="cell one text"/>
<Button
android:id="@+id/pdm_tooltip_btn1"
android:layout_column="1"
android:background="@drawable/tooltip_btn" />
<TextView
android:layout_column="2"
android:id="@+id/timeLabel"
android:textSize="14sp"
android:text="cell 3"
android:gravity="right"
android:padding="1dip"
android:visibility="visible"
android:layout_weight="1"/>
</TableRow>
</TableLayout>
</LinearLayout>更新后的图片:

发布于 2012-05-26 07:33:59
它需要一些摆弄。基本上,您必须在第一列之后添加一些空列(这将是第二列,因为它们是零索引的)。
因此,您将拥有:
<TableRow>
<TextView layout_column="0">
<Button layout_column="1">
<TextView layout_column="2"> // DUMMY!
<TextView layout_column="3">
</TableRow>现在,如果您愿意,您可以摆弄weight并相应地设置它。
第三列(第2列)将填充两个元素之间的空间,因此如果需要,可以对其进行拉伸。
https://stackoverflow.com/questions/10762328
复制相似问题