您的位置:首页 > 其它

为控件设置某几个边的边框

2017-07-28 15:33 92 查看
边框等一般都在drawable中设置,然后作为background。但是边框的设置只支持全方位的设置,如果想设置某个边的边框的话,有一种思路,就是使用两层绘制。比如我想在白色的控件左边加一个0.5dp黑色的边框。那么就先用黑色定义一个shape,然后再用白色定义一个,设置左边留出0.5dp。这样就达到了效果:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- This is the main color -->
<item>
<shape>
<corners android:topLeftRadius="2dp"/>
<!--    边框颜色 -->
<solid android:color="#8493a8"/>
</shape>
</item>
<item android:top="0.5dp" android:left="0.5dp">
<shape>
<corners android:topLeftRadius="2dp"/>
<!--     View填充颜色 -->
<solid android:color="#eceff4" />
</shape>
</item>

</layer-list>


代码中的例子在左边和上边设置了边框,并且左上角还有一个圆角。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: