2012-05-25 75 views
2

我一直在試圖在我的表格行下面安排我的單元格,使得第二個單元格的值(帶有背景圖像的按鈕)正好位於第一個單元格的文本右側。下面目前拉伸單元格2中的圖像,看起來像thisTableLayout單元格定位

有關如何停止拉伸和將單元格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> 

更新圖片: enter image description here

+0

請參閱下面的評論 – c12

回答

3

這會需要一些擺弄周圍。基本上,你將不得不在第1列之後添加一些空列(這將是第二列,因爲它們是零索引)。

所以,你將有:

<TableRow> 
    <TextView layout_column="0"> 

    <Button layout_column="1"> 

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

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

現在你可以用weight亂動,如果你看中並對其進行設置相應。

第三列(第2列)將填充兩個元素之間的空間,以便在需要時拉伸。

+0

感謝您的回覆。我放入一個具有一定寬度的虛擬文本視圖來推送圖像列,但是我無法在「發送消息」列的文本旁邊找到它(請參閱更新後的圖像)。它看起來像是單元格延伸到最長文本的長度。有沒有什麼辦法來移動消息發送單元內的圖像? – c12

+0

如果它們全部位於單獨的TableRow元素中,則不會影響其他單元格的寬度。這種行爲是另一個無法解釋的行爲,因爲一行不會以任何方式影響另一行的列。 – ScarletAmaranth

+0

我建議你編輯這個問題,這樣我可以編輯這個答案,因此它可以與誰試圖搜索同一個東西的人有關。你的問題可能對我來說只有:-)或者只是拋出一個新的問題或某事。 – ScarletAmaranth