2013-07-19 11 views

Odpowiedz

0

W kolumnach swojego TableLayout musisz użyć TextView, aby wyświetlić zawartość.

Więc dla pierwszej kolumny spróbować,

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

i dla drugiej kolumny spróbować,

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

Działa, dzięki. Ale komórki nie są równe szerokości (powinny być 50% (pierwsze) i 50% (drugie)). –

+0

@DarioRossi Kod wyświetlany przez Venky jest doskonały. Jaki jest problem w jej/jego kodzie? –

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

to działa. ale jest inny problem. Komórki w tabeli powinny być równe szerokości (powiedzmy 50%), ale w rzeczywistości mają 33% (pierwszy) i 66% (drugi). –

+0

Napisz pierwszy tekst w widoku Wight = 1 i drugi tekst wight = 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> 
Powiązane problemy