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

xiaoxiao2021-02-28  95

效果图:

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>

yechaoa 认证博客专家 Android Jetpack Flutter 小程序 专注于Android领域,同时探索于大前端方向,研究并应用落地前端、小程序、Flutter、Kotlin等相关热门技术点
转载请注明原文地址: https://www.6miu.com/read-52771.html

最新回复(0)