Android控件指定方向加边框

关键在于 

android:left="-2dp"
android:right="-2dp"

以下实现的就是上下加边框,左右不加(效果上);

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- This is the line -->
    <item>
        <shape>
            <padding
                android:bottom="0dp"
                android:left="-2dp"
                android:right="-2dp"
                android:top="0dp" />

            <solid android:color="#00ff00ff" />
        </shape>
    </item>
    <!-- This is the main color -->
    <item>
        <shape>
            <solid android:color="#00ff00ff" />

            <corners android:radius="0dip" />

            <size android:width="40dip" />

            <stroke
                android:width="2px"
                android:color="#9D9D9D" />
        </shape>
    </item>

</layer-list>


你可能感兴趣的:(Android控件指定方向加边框)