2011-12-23 34 views
8

Tôi đang phát triển màn hình sử dụng TableLayout. Ở đây tôi có thể dễ dàng tạo ra hai cột. nhưng làm cách nào tôi có thể tạo ba cột?cách tạo ba cột trong TableLayout

+2

thêm cột khác chính xác trong cùng một cách như bạn đã làm cho việc thêm hai cột –

Trả lời

14

đây một ví dụ:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:stretchColumns="1"> 
    <TableRow> 
     <TextView 
      android:text="first" 
      android:padding="3dip" /> 
     <TextView 
      android:text="second" 
      android:gravity="center" 
      android:padding="3dip" /> 
     <TextView 
      android:text="third" 
      android:gravity="right" 
      android:padding="3dip" /> 
    </TableRow> 

    <TableRow> 
     <TextView 
      android:text="first" 
      android:padding="3dip" /> 
     <TextView 
      android:text="second" 
      android:gravity="center" 
      android:padding="3dip" /> 
     <TextView 
      android:text="third" 
      android:gravity="right" 
      android:padding="3dip" /> 
    </TableRow> 
</TableLayout> 
+0

@Lucifer tôi nghĩ rằng bạn nên upvote đến nỗ lực của họ cũng nếu bạn tìm thấy câu trả lời của họ hữu ích. –

+0

Để có chiều rộng cố định bằng nhau cho tất cả các cột, hãy xem tại đây: http://stackoverflow.com/a/6647298/261436 – Sam

2

Đối với mỗi TableRow bạn phải thêm ba trẻ em thay vì hai. Điều này sẽ là ok cho bạn!

Hy vọng điều này sẽ hữu ích!

Các vấn đề liên quan