需要绘制一个背景,上面有圆角,然后四边有边框。是Shape很简单的用法。
大概是这样的,就是有几层绘制出来的。
使用layer-list标签
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<solid android:color="#FFFFFFFF"/>
</shape>
</item>
<item android:top="20dp" android:bottom="20dp" android:right="15dp" android:left="20dp">
<shape android:shape="rectangle">
<solid android:color="#000000"/>
<corners android:radius="15dp"/>
</shape>
</item>
<item android:top="20dp" android:bottom="20dp" android:right="20dp" android:left="20dp">
<shape android:shape="rectangle">
<solid android:color="#F39800"/>
<corners android:radius="8dp"/>
</shape>
</item>
</layer-list>
其中:item标签下的top、bottom、left、right属性相当于布局中的各个方向的margin,这一点比较重要。
本文介绍如何使用XML中的layer-list标签和shape元素来创建一个带有圆角和边框的背景效果。通过调整各层间的颜色、圆角半径及间距属性,可以轻松实现所需的视觉效果。
613

被折叠的 条评论
为什么被折叠?



