2011-08-27 28 views
36

thể trùng lặp:
What is the equivalent of “colspan” in an Android TableLayout?cột Spanning với TableLayout

Nó nói trong tài liệu cho TableLayout "Các tế bào có thể chiều dài cột, vì chúng có thể trong HTML" Tuy nhiên, tôi không thể tìm thấy bất kỳ cách nào để làm như vậy.

Cụ thể, tôi có một hàng với hai cột và cột khác có một cột. Tôi muốn hàng một cột kéo dài toàn bộ bảng. Có vẻ dễ dàng, nhưng tôi không thấy nó.

+1

Duplicate của: http://stackoverflow.com/q/2710793/165674 –

Trả lời

63

thêm android: layout_span = "3" để mở rộng 3 cột. Ví dụ:

 <TableRow> 
      <Button android:id="@+id/item_id" 
       android:layout_span="2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="item text" />  
     </TableRow> 
+3

Ahh, có nó, trong TableRow.LayoutParams: http://developer.android.com/ reference/android/widget/TableRow.LayoutParams.html –

+2

Tìm những tệp XML bố cục đó là khó khăn - dễ quên thuộc tính android: layout_ * nằm trong các javadocs riêng biệt. –

+1

-1, Giải pháp này không hoạt động khi văn bản của nút quá nhỏ. Ví dụ: khi văn bản chỉ là một '+' như trong ứng dụng máy tính, nút sẽ không phát triển cho đến khi nó bao gồm hai cột (nếu hai cột đó rộng hơn nút không có cộtSpan). – Zelphir

2

android: layout_span thực hiện thủ thuật.

dụ:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<TableRow> 
    <TextView android:id="@+id/info" 
     android:layout_span="2" 
     android:text="some text" 
     android:padding="3dip" 
     android:layout_gravity="center_horizontal" /> 
</TableRow> 
<TableRow> 
    <TextView android:text="some other text" 
     android:padding="3dip" /> 
    <TextView android:text="more text" 
     android:padding="3dip" /> 
</TableRow> 
</TableLayout> 
Các vấn đề liên quan