android 颜色渐变是指通知xml或者java代码,设置相关参数,是界面的某个指定的视图显示成从开始位置的颜色,逐渐过度到结尾位置的颜色的技术。
android颜色渐变的分类有:
LinearGradient线性渐变
RadialGradient镜像渐变
SweepGradient角度渐变
一、LinearGradient线性渐变顾名思义,是只颜色在一个直线方向上逐渐改变。
文件代码:
1
2
3
4
5
6
7
8
9
10
|
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<shape xmlns:android=
"http://schemas.android.com/apk/res/android"
android:shape=
"oval"
>
<gradient
android:endColor=
"#0000FF"
android:startColor=
"#FF0000"
android:type=
"linear"
/>
</shape>
|
效果:
二、RadialGradient镜像渐变镜像渐变就是楼主问的问题了:只要将type设置为oval,然后增加
android:gradientRadius
属性。
楼主特殊要求是圆形的话,需要在shape里面添加android:shape="oval"
文件代码:
1
2
3
4
5
6
7
8
9
10
11
|
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<shape xmlns:android=
"http://schemas.android.com/apk/res/android"
android:shape=
"oval"
>
<gradient
android:endColor=
"#0000FF"
android:gradientRadius=
"100%p"
android:startColor=
"#FF0000"
android:type=
"linear"
/>
</shape>
|
效果:
三、 SweepGradient角度渐变
是指以中心点为射线的一个断点,顺时针旋转所扫过的区域,颜色逐渐改变的一种渐变方式
1
2
3
4
5
6
7
8
9
|
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<shape xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<gradient
android:endColor=
"#0000FF"
android:startColor=
"#FF0000"
android:type=
"sweep"
/>
</shape>
|
效果图: