Skip to content

Commit 08728e5

Browse files
committed
1,修复bug
1 parent 19c6b74 commit 08728e5

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

library/src/main/java/com/flyjingfish/gradienttextviewlib/GradientTextView.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
122122

123123
@Override
124124
protected void onDraw(Canvas canvas) {
125+
TextPaint backGroundTextPaint = backGroundText.getPaint();
125126
if (gradientStrokeColor){
126-
TextPaint backGroundTextPaint = backGroundText.getPaint();
127127
float currentAngle = strokeAngle;
128128
if (strokeRtlAngle && isRtl){
129129
currentAngle = - strokeAngle;
@@ -132,6 +132,8 @@ protected void onDraw(Canvas canvas) {
132132

133133
@SuppressLint("DrawAllocation") LinearGradient linearGradient = new LinearGradient(xy[0], xy[1], xy[2], xy[3], gradientStrokeColors, gradientStrokePositions, Shader.TileMode.CLAMP);
134134
backGroundTextPaint.setShader(linearGradient);
135+
}else {
136+
backGroundTextPaint.setShader(null);
135137
}
136138
backGroundText.draw(canvas);
137139

@@ -145,6 +147,8 @@ protected void onDraw(Canvas canvas) {
145147

146148
@SuppressLint("DrawAllocation") LinearGradient linearGradient = new LinearGradient(xy[0], xy[1], xy[2], xy[3], gradientColors, gradientPositions, Shader.TileMode.CLAMP);
147149
getPaint().setShader(linearGradient);
150+
}else {
151+
getPaint().setShader(null);
148152
}
149153
super.onDraw(canvas);
150154

@@ -207,6 +211,8 @@ public int getStrokeWidth() {
207211

208212
public void setStrokeWidth(int strokeWidth) {
209213
this.strokeWidth = strokeWidth;
214+
TextPaint textPaint = backGroundText.getPaint();
215+
textPaint.setStrokeWidth(strokeWidth);
210216
invalidate();
211217
}
212218

@@ -216,7 +222,7 @@ public int[] getGradientStrokeColors() {
216222

217223
public void setGradientStrokeColors(int[] gradientStrokeColors) {
218224
this.gradientStrokeColors = gradientStrokeColors;
219-
gradientStrokeColor = true;
225+
gradientStrokeColor = gradientStrokeColors != null;
220226
invalidate();
221227
}
222228

@@ -245,7 +251,7 @@ public float[] getGradientPositions() {
245251

246252
public void setGradientPositions(float[] gradientPositions) {
247253
this.gradientPositions = gradientPositions;
248-
gradientColor = true;
254+
gradientColor = gradientPositions != null;
249255
invalidate();
250256
}
251257

@@ -292,6 +298,7 @@ public int getStrokeTextColor() {
292298
public void setStrokeTextColor(int strokeTextColor) {
293299
this.strokeTextColor = strokeTextColor;
294300
backGroundText.setTextColor(strokeTextColor);
301+
gradientStrokeColor = false;
295302
invalidate();
296303
}
297304
}

0 commit comments

Comments
 (0)