2013-07-19 30 views

Trả lời

0

Trong các cột của TableLayout bạn phải đang sử dụng TextView để hiển thị nội dung.

Vì vậy, cho cột đầu tiên thử loại này,

<TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="right" 
     android:text="Key" 
     android:textColor="@android:color/black"/> 

và cho cột thứ hai cố gắng này,

<TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="left" 
     android:text="Value" 
     android:textColor="@android:color/black"/> 
+0

Nó hoạt động, Cảm ơn. Nhưng các ô không bằng chiều rộng (chúng phải là 50% (đầu tiên) và 50% (giây)). –

+0

@DarioRossi Các mã được hiển thị bởi Venky là hoàn hảo. Vấn đề trong mã của cô ấy là gì? –

2
Use TextViews and gravity 

<TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="right" 
       android:text="key" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="left" 
       android:text="value" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="right" 
       android:text="More key" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="left" 
       android:text="More value" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="right" 
       android:text="Even more key" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="left" 
       android:text="Even more value" /> 
     </TableRow> 
    </TableLayout> 
+0

nó hoạt động. nhưng có một vấn đề khác. Các ô trong bảng phải bằng với chiều rộng (giả sử 50%) nhưng trên thực tế chúng có 33% (đầu tiên) và 66% (thứ hai). –

+0

Viết TextView đầu tiên wight = 1 và TextView wight thứ hai = 2 – Venky

1
Write first TextView wight=1 and second TextView wight=2 


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="right" 
       android:text="key" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="2" 
       android:gravity="left" 
       android:text="value" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="right" 
       android:text="More key" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="2" 
       android:gravity="left" 
       android:text="More value" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="right" 
       android:text="Even more key" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="2" 
       android:gravity="left" 
       android:text="Even more value" /> 
     </TableRow> 
    </TableLayout> 

</LinearLayout> 
Các vấn đề liên quan