-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaintShaderBasic.java
More file actions
55 lines (48 loc) · 1.55 KB
/
PaintShaderBasic.java
File metadata and controls
55 lines (48 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.work.basic;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
/**
* Title: LinearShaderView
* <p>
* Description:
* </p>
*
* @author Changbao
* @date 2018/12/13 13:50
*/
public class PaintShaderBasic extends View {
public PaintShaderBasic(Context context) {
super(context);
}
public PaintShaderBasic(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public PaintShaderBasic(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
//LinearGradient
Shader shaderLinear = new LinearGradient(0, 0, 300, 300,
Color.parseColor("#E91E63"),
Color.parseColor("#2196F3"), Shader.TileMode.CLAMP);
paint.setShader(shaderLinear);
canvas.drawCircle(150, 150, 100, paint);
//RadialGradient
Shader shaderRadial = new RadialGradient(280, 280, 100,
Color.parseColor("#E91E63"),
Color.parseColor("#2196F3"), Shader.TileMode.CLAMP);
paint.setShader(shaderRadial);
canvas.drawCircle(280, 280, 100, paint);
}
}