Android TableLayout TableRow自定义样式

1 篇文章 0 订阅
1 篇文章 0 订阅

<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>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值