[英]How to create custom Table Layout with headers and grid lines
創建一個可繪制的cell_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape= "rectangle" >
<stroke android:width="0.5dp" android:color="#4E4E4E"/>
</shape>
在你的styles.xml 中定義你的自定義單元格樣式
<style name="Cell">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:background">@drawable/cell_shape</item>
<item name="android:gravity">center</item>
<item name="android:paddingTop">8dp</item>
<item name="android:paddingBottom">8dp</item>
<item name="android:textSize">12sp</item>
</style>
table_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView
style="@style/Cell"
android:text="\"
android:textStyle="bold" />
<TextView
style="@style/Cell"
android:text="My Title 1"
android:textStyle="bold" />
<TextView
style="@style/Cell"
android:text="My Title 2"
android:textStyle="bold" />
<TextView
style="@style/Cell"
android:text="My Title 3"
android:textStyle="bold" />
</TableRow>
<TableRow>
<TextView
style="@style/Cell"
android:text="Arg 1"
android:textStyle="bold" />
<ImageButton
style="@style/Cell"
android:src="@mipmap/ic_launcher" />
<ImageButton
style="@style/Cell"
android:src="@mipmap/ic_launcher" />
<ImageButton
style="@style/Cell"
android:src="@mipmap/ic_launcher" />
</TableRow>
<!--Next Rows...-->
</TableLayout>
<!--//..-->
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.