当前位置:   article > 正文

安卓渐变色_android:angle=

android:angle=

先举个例子:
如图:三种颜色从左往右渐变

在这里插入图片描述

以下为各个属性详解:

1.angle
android:angle=“Integer” :当android:type=“linear” 时,angle为渐变的角度:0 代表从左往右渐变,90 从上到下,180从右往左,360左往右。
值为 0 到 360,必须是45的倍数或0。(ps:type不等于linear时是不起作用的)

2.startColor、centerColor、endColor
android:startColor=“color” :渐变开始位置的颜色,值为16色类型,例:#448AFF 。
android:centerColor=“color” :渐变中间位置的颜色
android:endColor=“color” 渐变结束位置的颜色
(ps:当android:type="linear"时,android:centerX="Integer"或android:centerY=“Integer” 可以更改中间颜色的位置)

3.type
android:type=""
3.1:值为linear时,线性渐变:上面已讲;

3.2:值为:sweep:扫描渐变,也就是从右旋转一圈渐变,起始位置默认中间(就是中间三个颜色交点那),例:
在这里插入图片描述

加入这两个属性,可以更改起始位置,根据X、Y的值确定起始位置。其值为 0 到 1
android:centerX=“0.5”
android:centerY=“0.8”

3.3:值为radial时:径向渐变,必须配合 android:gradientRadius=""(圆形渐变的大小,值可以为纯数字或 sp 等等) 使用,例:

在这里插入图片描述

加入这两个属性,可以更改起始位置,根据X、Y的值确定起始位置。其值为 0 到 1
android:centerX=“0.5”
android:centerY=“0.8”

举例图,圆形渐变:
在这里插入图片描述

代码:

<?xml version="1.0" encoding="utf-8"?>

<!--
android:shape="oval":画圆
size 标签:圆的宽高
-->
<size
    android:width="120dp"
    android:height="120dp"/>

<gradient
    android:type="linear"
    android:angle="0"
    android:startColor="#448AFF"
    android:centerColor="@color/colorWhite"
    android:endColor="#69F0AE"/>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/420656
推荐阅读
相关标签
  

闽ICP备14008679号