2012-08-02 37 views
2

我如何突出顯示tablelayout的邊框... 即時通訊使用roundshape.xml,它具有形狀作爲背景必須有一些方法,我可以讓你的tablelayout邊框...android:如何顯示TableLayout的邊框

roundshape.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 

    <corners android:radius="5dip" /> 

    <gradient 
     android:angle="270" 
     android:endColor="@color/WhiteSmoke" 
     android:startColor="@color/WhiteSmoke" 
     android:type="linear" /> 

</shape> 

的WhiteSmoke =#F5F5F5

main.xml中

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

    <TableLayout 
     android:layout_width="400dp" 
     android:layout_height="400dp" 
     android:background="@drawable/roundshape" 
     > 

     <TableRow 
      android:id="@+id/tableRow1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

     </TableRow> 

     <TableRow 
      android:id="@+id/tableRow2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 
     </TableRow> 

     <TableRow 
      android:id="@+id/tableRow3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 
     </TableRow> 

     <TableRow 
      android:id="@+id/tableRow4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 
     </TableRow> 
    </TableLayout> 

</LinearLayout> 
+0

可能重複[我怎樣才能建立在Android的邊框的表格?] (http://stackoverflow.com/questions/2108456/how-can-i-create-a-table-with-borders-in-android) – prolink007 2012-08-02 16:31:04

回答

2

我認爲這可能幫助ü..辦理代碼U將找出招

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

    <TableLayout 
     android:layout_width="400dp" 
     android:layout_height="400dp" 
     android:background="@drawable/roundshape" > 

     <TableRow 
      android:layout_width="fill_parent" 
      android:layout_height="1px" 
      android:background="#ff9" > 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="1px" 
       android:text="" /> 
     </TableRow> 

     <TableRow 
      android:id="@+id/tableRow1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:text="this is amazing" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="fill_parent" 
      android:layout_height="1px" 
      android:background="#ff9" > 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="1px" 
       android:text="" /> 
     </TableRow> 

     <TableRow 
      android:id="@+id/tableRow2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:text="this is amazing" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="fill_parent" 
      android:layout_height="1px" 
      android:background="#ff9" > 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="1px" 
       android:text="" /> 
     </TableRow> 

     <TableRow 
      android:id="@+id/tableRow3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:text="this is amazing" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="fill_parent" 
      android:layout_height="1px" 
      android:background="#ff9" > 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="1px" 
       android:text="" /> 
     </TableRow> 

     <TableRow 
      android:id="@+id/tableRow4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:text="this is amazing" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="fill_parent" 
      android:layout_height="1px" 
      android:background="#ff9" > 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="1px" 
       android:text="" /> 
     </TableRow> 
    </TableLayout> 

</LinearLayout> 
0

這裏已經有一篇非常類似的文章。

從耶西

我對這個問題的解決辦法是把一個XML繪製資源上的每一個細胞的 背景場。通過這種方式,您可以使用所需單元格的邊框定義一個 形狀。 唯一的不便之處在於極端單元格的邊框的寬度只有其他一半的寬度的一半,但如果表格填滿了整個屏幕,則沒有問題。

Here is the reference to this resource.