2013-08-01 18 views
10

Poniżej znajduje się mój kod tabeli. Mój ekran wygląda tak: http://imgur.com/dFP298o, ale chcę, aby wyglądał tak: http://imgur.com/YuYJiJx. Jak mogę dodać ramki wokół każdego wiersza i wokół układu tabeli?Jak dodać obramowanie wokół TableLayout?

<TableLayout 
    android:id="@+id/table2" 
    android:layout_width="fill_parent" 
    android:layout_below="@+id/test_button_text23" 
    android:layout_marginLeft="45dp" 
    android:layout_marginBottom="25dp" 
    android:layout_marginRight="45dp"  
    android:layout_height="fill_parent" 
    android:stretchColumns="*" > 

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

     <TextView 
      android:gravity="left" 
      android:text="Quantity" 
      android:textStyle="bold" /> 

     <TextView 
      android:gravity="center" 
      android:textStyle="bold" 
      android:text="Item" /> 

    </TableRow> 

</TableLayout>  

 

<?xml version="1.0" encoding="utf-8"?> 
<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <TextView 
     android:id="@+id/localTime" 
     android:textColor="#000000" 
     android:gravity="left" /> 

    <TextView 
     android:id="@+id/apprentTemp" 
     android:textColor="#000000" 
     android:gravity="center" /> 

</TableRow> 

 

View row = getLayoutInflater().inflate(R.layout.rows, null); 
((TextView) row.findViewById(R.id.localTime)).setText(item.getString("Item")); 
((TextView) row.findViewById(R.id.apprentTemp)).setText(item.getString("Quantity")); 
+1

Spójrz na tę drugą odpowiedź. http://stackoverflow.com/a/7379990/2324810 – Hadriel

+0

jego tak mylące po prostu edytuj mój kod, proszę – user2589245

Odpowiedz

20

Aby utworzyć obramowanie wokół wierszy tabeli i całego układu tabeli, należy utworzyć rozciągliwej służyć jako granicy a następnie ustawić go jako tło dla swoich wierszy.

Na przykład:

res/odkształcalne/border.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape= "rectangle"> 
    <solid android:color="#000000"/> 
    <stroke android:width="1dp" android:color="#000000"/> 
</shape> 

res/layout/your_layout.xml

<TableLayout 
    android:id="@+id/table2" 
    android:layout_width="fill_parent" 
    android:layout_below="@+id/test_button_text23" 
    android:layout_marginLeft="45dp" 
    android:layout_marginBottom="25dp" 
    android:layout_marginRight="45dp" 
    android:layout_height="fill_parent" 
    android:stretchColumns="*"> 

    <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/border"> 

      <TextView 
       android:gravity="left" 
       android:text="Quantity" 
       android:background="@drawable/border" 
       android:textStyle="bold"/> 

      <TextView 
       android:gravity="center" 
       android:textStyle="bold" 
       android:background="@drawable/border" 
       android:text="Item" /> 

    </TableRow> 

</TableLayout> 

To nie będzie wyglądać dokładnie tak, jak zdjęcie, które opublikowałeś, ale graj z nim, aby uzyskać to, czego chcesz.

+5

pasowałoby do obrazu o wiele lepiej Wierzę, jeśli użyłeś insted –

Powiązane problemy