2

我一直在尝试将我的单元格排列在下面的表格行中,这样第二个单元格的值(带有背景图像的按钮)就在第一个单元格的文本右侧。下面当前拉伸单元格 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>

更新图像: 在此处输入图像描述

4

1 回答 1

5

这将需要一些摆弄。基本上,您必须在第 1 列之后添加一些空列(这将是第二列,因为它们是零索引的)。

所以你将拥有:

<TableRow>
   <TextView layout_column="0">

   <Button layout_column="1">

   <TextView layout_column="2"> // DUMMY!

   <TextView layout_column="3">
</TableRow>

现在,您可以随意摆弄weight并进行相应的设置。

第三列(第 2 列)将填充两个元素之间的空间,以便在需要时将其拉伸。

于 2012-05-25T23:33:58.733 回答