Android Paint 绘制空心渐变圆角矩形

在onDraw方法中绘制空心渐变圆角矩形

Paint paint =new Paint();
paint.setAntiAlias(true);
// 渐变颜色
int[] mColors = {0xFFFF0000,0xFF00FF00,0xFF0000FF};
// 渐变范围
float[] mGradientPositions = {0,0.4f,1};
// 渐变方向,从(0,0)到(100,100),相当于从左上到右下。
paint.setShader(new LinearGradient(0,0,100,100,mColors,mGradientPositions, Shader.TileMode.CLAMP));
// 描边宽度
paint.setStrokeWidth(2);
// 设置画笔绘制样式
paint.setStyle(Paint.Style.STROKE);
// 绘制矩形范围
RectF rectF =new RectF(0,0,100,100);
// 绘制圆角矩形
canvas.drawRoundRect(rectF,10,10,mPaint);

你可能感兴趣的:(Android Paint 绘制空心渐变圆角矩形)