<TableLayout
android:id="@+id/top01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/CustomTableLayout">
<TableRow style="@style/CustomTableRow">
<TextView
android:layout_width="30dp"
android:layout_height="match_parent"
style="@style/CustomTextView_key"
android:text="名称"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
style="@style/CustomTextView_value"/>
<TextView
android:layout_width="30dp"
android:layout_height="match_parent"
style="@style/CustomTextView_key"
android:text="属性" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
style="@style/CustomTextView_value"/>
</TableRow>
<TableRow style="@style/CustomTableRow">
<TextView
android:layout_width="30dp"
android:layout_height="match_parent"
style="@style/CustomTextView_key"
android:text="名称1"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
style="@style/CustomTextView_value"/>
<TextView
android:layout_width="30dp"
android:layout_height="match_parent"
style="@style/CustomTextView_key"
android:text="属性1" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
style="@style/CustomTextView_value"/>
</TableRow>
</TableLayout>
style.xml中定义
<style name="CustomTableLayout">
<item name="android:divider">@drawable/table_v_divider</item>
<item name="android:orientation">vertical</item>
<item name="android:showDividers">middle|beginning|end</item>
<item name="android:layerType">software</item>
</style>
<style name="CustomTableRow">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:divider">@drawable/table_h_divider</item>
<item name="android:orientation">horizontal</item>
<item name="android:showDividers">middle|beginning|end</item>
</style>
<style name="CustomTextView_key">
<item name="android:gravity">center</item>
<item name="android:textColor">@color/orange</item>
<item name="android:textSize">@dimen/font_small</item>
<item name="android:layout_weight">1</item>
</style>
<style name="CustomTextView_value">
<item name="android:layout_marginLeft">5dp</item>
<item name="android:layout_marginRight">5dp</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textColor">@color/gray_deep</item>
<item name="android:textSize">@dimen/font_small</item>
<item name="android:layout_weight">2</item>
</style>
res/drawable/table_h_divider.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size
android:width="0.3dp" />
<solid android:color="@color/main_color" />
</shape>
res/drawable/table_v_divider.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:height="0.3dp" />
<solid android:color="@color/main_color" />
</shape>