Как добавить границу вокруг TableLayout? - программирование
Подтвердить что ты не робот

Как добавить границу вокруг TableLayout?

Ниже мой код таблицы. Мой экран выглядит следующим образом http://imgur.com/dFP298o, но я хочу, чтобы он выглядел следующим образом http://imgur.com/YuYJiJx. Как я могу добавить границы вокруг каждой строки и вокруг макета таблицы?

<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"));
4b9b3361

Ответ 1

Чтобы создать рамку вокруг строк таблицы и вокруг макета таблицы, необходимо создать объект рисования, который будет служить границей, а затем установить его в качестве фона для ваших строк.

Например:

Рез/рисуем /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="#ffffff"/>
   <stroke android:width="1dp" android:color="#000000"/>
</shape>

разреш/макет/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>  

Это будет выглядеть не совсем так, как на картинке, которую вы разместили, но поиграйте с ней, чтобы получить то, что вы хотите.