Android drawable 文件使用(一)layer-list - 相逢的人会再相逢 - 博客频道 - CSDN.NET

1,747 阅读1分钟
原文链接: blog.csdn.net

今天的需求:  ,,着重看三个框中间的两条竖线,如果直接把3个textview的background引用一个shape文件 ,那么效果实际上  中间两道竖线会重叠变粗,需要使用layer-list 来处理 ; 话不多说上代码:

“本月”的shape :

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke
        android:width="1dp"
        android:color="@color/home_title" />
    <corners
        android:bottomRightRadius="3dp"
        android:topRightRadius="3dp" />
</shape>
“今天”的   

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke
        android:width="1dp"
        android:color="@color/home_title" />
    <corners
        android:bottomLeftRadius="3dp"
        android:topLeftRadius="3dp" />
</shape>
“本周”
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:left="-2dp"
        android:right="-2dp">
        <shape>
            <stroke
                android:width="1dp"
                android:color="@color/home_title" />

        </shape>
    </item>
</layer-list>
重点是这里:  android:left="-2dp"  android:right="-2dp">  把左侧右侧的宽度减掉即可,而且请看之前我设置的宽度是 <span style="font-family: Arial, Helvetica, sans-serif;">android:width="1dp  ,试试就知道了  就要多减 1dp 。</span>