当前位置:首页 > 科技  > 软件

Android开发之渐变色,你学会了吗?

来源: 责编: 时间:2024-01-16 10:14:57 292观看
导读android.graphics中提供了有关Gradient类,包含LinearGradient线性渐变、 RadialGradient径向渐变和SweepGradient梯度渐变,它们的继承自android.graphics.Shader。LinearGradient 线性渐变LinearGradient(float x0, flo

android.graphics中提供了有关Gradient类,包含LinearGradient线性渐变、 RadialGradient径向渐变和SweepGradient梯度渐变,它们的继承自android.graphics.Shader。PWa28资讯网——每日最新资讯28at.com

LinearGradient 线性渐变

LinearGradient(float x0, float y0, float x1, float y1, int[] colors, float[] positions, Shader.TileMode tile)LinearGradient(float x0, float y0, float x1, float y1, int color0, int color1, Shader.TileMode tile)

参数PWa28资讯网——每日最新资讯28at.com

说明PWa28资讯网——每日最新资讯28at.com

x0PWa28资讯网——每日最新资讯28at.com

渐变线起点的x坐标PWa28资讯网——每日最新资讯28at.com

y0PWa28资讯网——每日最新资讯28at.com

渐变线起点的y坐标PWa28资讯网——每日最新资讯28at.com

x1PWa28资讯网——每日最新资讯28at.com

渐变线末端的x坐标PWa28资讯网——每日最新资讯28at.com

y1PWa28资讯网——每日最新资讯28at.com

渐变线末端的y坐标PWa28资讯网——每日最新资讯28at.com

colorsPWa28资讯网——每日最新资讯28at.com

沿着渐变线分布的颜色数组PWa28资讯网——每日最新资讯28at.com

color0PWa28资讯网——每日最新资讯28at.com

渐变线开始处的颜色PWa28资讯网——每日最新资讯28at.com

color1PWa28资讯网——每日最新资讯28at.com

渐变线末端的颜色PWa28资讯网——每日最新资讯28at.com

positionsPWa28资讯网——每日最新资讯28at.com

颜色数组中每个对应颜色的相对位置[0,1]。如果为null,则颜色沿线均匀分布PWa28资讯网——每日最新资讯28at.com

tilePWa28资讯网——每日最新资讯28at.com

着色器平铺模式PWa28资讯网——每日最新资讯28at.com

Paint paint =new Paint();//两个坐标形成变量,规定了渐变的方向和间距大小,着色器为镜像LinearGradient linearGradient =new LinearGradient(0,0,200,0, Color.RED,Color.BLUE, Shader.TileMode.MIRROR);paint.setShader(linearGradient);paint.setStrokeWidth(50);canvas.drawLine(0,getMeasuredHeight()/2,getMeasuredWidth(),getMeasuredHeight()/2, paint);

图片图片PWa28资讯网——每日最新资讯28at.com

RadialGradient 径向/放射渐变

RadialGradient(float x, float y, float radius, int[] colors, float[] positions, Shader.TileMode tile)RadialGradient(float x, float y, float radius, int color0, int color1, Shader.TileMode tile)

参数PWa28资讯网——每日最新资讯28at.com

说明PWa28资讯网——每日最新资讯28at.com

xPWa28资讯网——每日最新资讯28at.com

半径中心的x坐标PWa28资讯网——每日最新资讯28at.com

yPWa28资讯网——每日最新资讯28at.com

半径中心的y坐标PWa28资讯网——每日最新资讯28at.com

radiusPWa28资讯网——每日最新资讯28at.com

渐变的圆的半径PWa28资讯网——每日最新资讯28at.com

colorsPWa28资讯网——每日最新资讯28at.com

颜色分布在圆的中心和边缘之间PWa28资讯网——每日最新资讯28at.com

color0PWa28资讯网——每日最新资讯28at.com

圆圈中心的颜色PWa28资讯网——每日最新资讯28at.com

color1PWa28资讯网——每日最新资讯28at.com

圆圈边缘的颜色PWa28资讯网——每日最新资讯28at.com

positionsPWa28资讯网——每日最新资讯28at.com

颜色数组中每个对应颜色的相对位置[0,1]。如果为null,则颜色沿线均匀分布PWa28资讯网——每日最新资讯28at.com

tilePWa28资讯网——每日最新资讯28at.com

着色器平铺模式PWa28资讯网——每日最新资讯28at.com

paint =new Paint();radialGradient =new RadialGradient(240,360,200, new int[]{Color.BLUE, Color.GREEN, Color.RED },null, Shader.TileMode.CLAMP);paint.setShader(radialGradient);canvas.drawCircle(240,360,200,paint);

图片图片PWa28资讯网——每日最新资讯28at.com

SweepGradient 扫描/梯度/扇形渐变

SweepGradient(float x, float y, int[] colors, float[] positions)SweepGradient(float x, float y, int color0, int color1)

参数PWa28资讯网——每日最新资讯28at.com

说明PWa28资讯网——每日最新资讯28at.com

xPWa28资讯网——每日最新资讯28at.com

中心的x坐标PWa28资讯网——每日最新资讯28at.com

yPWa28资讯网——每日最新资讯28at.com

中心的y坐标PWa28资讯网——每日最新资讯28at.com

colorsPWa28资讯网——每日最新资讯28at.com

颜色分布在中心周围,阵列中必须至少有2种颜色PWa28资讯网——每日最新资讯28at.com

color0PWa28资讯网——每日最新资讯28at.com

扫描开始时使用的颜色PWa28资讯网——每日最新资讯28at.com

color1PWa28资讯网——每日最新资讯28at.com

扫描结束时使用的颜色PWa28资讯网——每日最新资讯28at.com

positionsPWa28资讯网——每日最新资讯28at.com

颜色数组中每个对应颜色的相对位置[0,1]。如果为null,则颜色沿线均匀分布PWa28资讯网——每日最新资讯28at.com

paint =new Paint();int[] colors = new int[]{Color.GREEN, Color.GREEN, Color.BLUE, Color.RED, Color.RED};sweepGradient = new SweepGradient(240, 360,colors,null);paint.setShader(sweepGradient);canvas.drawCircle(x,y,200,paint);

图片图片PWa28资讯网——每日最新资讯28at.com

本文链接:http://www.28at.com/showinfo-26-62356-0.htmlAndroid开发之渐变色,你学会了吗?

声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。邮件:2376512515@qq.com

上一篇: 阿里二面:要保证消息不丢失,又不重复,消息队列怎么选型?

下一篇: Spring Boot:如何快速集成Mybatis和Thymeleaf

标签:
  • 热门焦点
Top