android 的TableLayouyt的邊框的簡單應用

來源:互聯網
上載者:User

 TableLayouyt布局難的是邊框的控制,

   首先看下面圖片

                     

   在TableLayout中沒有boder屬性,很讓人糾結,學人家html多好,不知道google是怎麼想的.不廢話了,說下邊框機制.

   TableLayout 邊框布局:其實就背景色套背景色,中間重疊的部分就是我們要的邊框

   <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/gray" ><!-- 在這裡我們設定tableRow的背景色, TableRow裡面載入的是view-->  

 <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@color/white"  <!--在設定載入view的背景色,重要的是加上android:layout_margin 這個屬性,讓view和row有一段的距離,這樣邊框就出來了. -->
                android:gravity="center"
                android:layout_margin="1dp" 
                android:text="日期" />

  這是一種方式,不過你認真會發現中間的分割線比兩邊的最上面最下面的粗,因為我們在每一個textview中加上了 android:layout_margin="1dp"這個屬性,則左右上下都margin為1,第二個表格左邊下面右邊都重疊了,所以會變粗,如果想調整則可以通過詳細設定margin的上下左右等值,

 其實你把線條設定細點會不太明顯,這樣就ok了.

   另外一種方法,我們可以定製表格view的背景,通過shape.xml檔案,我們只需要在view中引用即可.這種方法簡單,建議大家以後都用這種.

     <shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- 填充顏色 -->
    <gradient
        android:angle="0"
        android:endColor="#FFFFFF"
        android:startColor="#FFFFFF" />
    <!-- 四角的弧度 -->
    <stroke
        android:width="0.5dp"
        android:color="#DBDBDB" />
    <!-- 角度 -->
    <corners android:radius="3dp" />

    <padding
        android:bottom="5dp"
        android:left="5dp"
        android:right="5dp"
        android:top="5dp" />

</shape>

以上是簡單對邊框的應用,要想做出比較棒的顯示 需要詳細認真布局,不過知道方法實現就OK了.

    

   

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.