您的位置:首页 > 其它

shape颜色渐变、圆角、半圆角、边框、填充

2017-08-06 15:33 316 查看
效果图:





1、shape:

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

<!--圆角-->
<corners
android:radius="5dp"
android:topLeftRadius="30dp"
android:bottomRightRadius="30dp"/>

<!--填充颜色-->
<solid android:color="#000"/>

<!--边框-->
<stroke
android:color="#808080"
android:width="2dp"/>

<!--渐变-->
<gradient
android:startColor="#f52"
android:centerColor="#f92"
android:endColor="#fe2"
android:angle="180"/>

</shape>

渐变的颜色把填充的颜色顶了,所以是可以去掉solid的

2、关于gradient的angle参数:

0 是从左到右

90是从下到上

180是从右到左

270是从上到下

360==0

3、还有一个type参数:

linear 线性渐变(默认)

radial 环形渐变

sweep 扇形渐变

渐变一般给个开始颜色和结束颜色,然后指定一下方向就行了

4、两边半圆角:

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

<corners android:radius="999dp"/>

<stroke
android:width="1dp"
android:color="@color/colorPrimary"/>

<padding
android:bottom="10dp"
android:left="20dp"
android:right="20dp"
android:top="10dp"/>

</shape>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: