TableLayout の周囲に境界線を追加するにはどうすればいいですか? 質問する

TableLayout の周囲に境界線を追加するにはどうすればいいですか? 質問する

以下は私のテーブルコードです。画面は次のようになりますhttps://i.sstatic.net/U5ppn.jpgでもこんな感じにしたい出典: http://i.sstatic.net/gFQZw.jpg各行とテーブルレイアウトの周囲に境界線を追加するにはどうすればよいですか?

<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

テーブル行とテーブル レイアウトの周囲に境界線を作成するには、境界線として機能する描画可能オブジェクトを作成し、それを行の背景として設定する必要があります。

例えば:

res/drawable/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>

res/レイアウト/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>  

これは投稿した写真とまったく同じにはなりませんが、お好みの結果が得られるよう調整してみてください。

おすすめ記事