Android UI效果之绘图篇(四)
作者:_Hi_xiaoyu 时间:2022-08-07 19:26:12
上一篇博文说到了Shader的五个子类
- BitmapShader
- LinearGradient
- RadialGradient
- SweepGradient
- ComposeShader
其中BitmapShader和LinearGradient已经做了说明,今天就把剩余的三个Shader补充一下
3. RadialGradient
先看下构造方法
/**
@param centerX 中心X坐标
@param centerY 中心Y坐标
@param radius 半径
@param centerColor 开始颜色
@param edgeColor 结束颜色
@param tileMode The Shader tiling mode
*/
public RadialGradient(float centerX, float centerY, float radius,int centerColor, int edgeColor, @NonNull TileMode tileMode)
public RadialGradient(float centerX, float centerY, float radius,@NonNull int colors[], @Nullable float stops[], @NonNull TileMode tileMode)
第一个构造方法已经进行了文档说明,比较简单,而第二个构造方法和LinearGradient同理,就不再赘述,使用方法也基本类似,这里直接看下效果即可
RadialGradient rg = new RadialGradient(canvas.getWidth()/2, canvas.getHeight()/2, 200, 0xffff0000, 0xff0000ff, Shader.TileMode.[CLAMP|REPEAT |MIRROR]);
paint.setShader(rg);
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), paint);
① CLAMP
② REPEAT
③ MIRROR
1、SweepGradient
/**
*
* @param cx 中心X坐标
* @param cy 中心Y坐标
* @param color0 开始颜色
* @param color1 结束颜色
*/
public SweepGradient(float cx, float cy, int color0, int color1)
第一个构造方法比较简单,没什么好说的,效果的话类似于做煎饼皮,展开选择360度。主要看第二个构造方法
public SweepGradient(float cx, float cy,int colors[], float positions[])
cx、cy没什么好说的,中心点坐标,colors颜色数组,主要是positions,positions中每个item的取值范围在0f-1f之间,对于colors中相应颜色在图形中的位置
int[] colors = {0xffff0000, 0xff00ff00, 0xffffff00, 0xffffffff,0xff000000};
float[] positions = {0f,0.25f, 0.5f, 0.75f, 1f};
SweepGradient rg = new SweepGradient(canvas.getWidth() / 2, canvas.getHeight() / 2, colors, positions);
paint.setShader(rg);
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), paint);
ComposeShader
ComposeShader(Shader shaderA, Shader shaderB, Xfermode mode)
ComposeShader(Shader shaderA, Shader shaderB, PorterDuff.Mode mode)
ComposeShader,混合Shader,看到构造方法,大家应该就已经会用ComposeShader,其实就是对两个shader进行取并集交集操作,遗忘了的同学可以翻看下上一篇文章,这里就不再演示了。
标签:Android,UI,绘图
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SWT(JFace)体验之ApplicationWindow
2023-01-02 09:59:43
Spring Data Jpa实现分页和排序代码实例
2021-11-08 01:19:48
Java Swing JLabel标签的使用方法
2021-09-16 05:48:13
![](https://img.aspxhome.com/file/2023/3/68573_0s.jpg)
MyBatis学习教程(五)-实现关联表查询方法详解
2021-06-23 21:04:04
![](https://img.aspxhome.com/file/2023/9/74979_0s.png)
C#学习笔记之状态模式详解
2021-09-15 21:56:08
![](https://img.aspxhome.com/file/2023/0/122710_0s.png)
C# WinForm打开PDF文件并在窗体中显示
2023-11-14 10:47:49
Java用户登录验证代码
2022-05-11 16:45:46
Spring Boot详解配置文件的用途与用法
2022-08-01 20:37:27
![](https://img.aspxhome.com/file/2023/4/77954_0s.png)
Java并发包线程池ThreadPoolExecutor的实现
2022-11-10 09:52:41
![](https://img.aspxhome.com/file/2023/3/64383_0s.jpg)
C++中String类型的逆序方式
2023-11-19 05:46:52
Java Spring Security认证与授权及注销和权限控制篇综合解析
2021-07-04 08:14:17
![](https://img.aspxhome.com/file/2023/7/92537_0s.png)
Java import导入及访问控制权限修饰符原理解析
2023-08-17 21:42:59
Mybatis中xml的动态sql实现示例
2023-11-29 17:09:36
Java将byte[]转图片存储到本地的案例
2021-08-30 08:19:12
Android单选按钮对话框用法实例分析
2023-03-27 17:10:52
![](https://img.aspxhome.com/file/2023/9/100599_0s.png)
MyBatis中XML 映射文件中常见的标签说明
2023-01-07 08:02:59
Java Object类中的常用API介绍
2023-11-09 01:51:00
Java maven详细介绍
2022-10-12 06:45:31
![](https://img.aspxhome.com/file/2023/8/99928_0s.png)
C#事务处理(Execute Transaction)实例解析
2022-04-12 15:32:43
关于maven:pom文件的使用解析
2022-02-08 06:21:41