Skip to content

Commit d6ecd64

Browse files
committed
优化防止过度绘制
1 parent fe0c2fa commit d6ecd64

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
```gradle
3939
dependencies {
40-
implementation 'com.github.FlyJingFish:GradientTextView:1.1.1'
40+
implementation 'com.github.FlyJingFish:GradientTextView:1.1.2'
4141
}
4242
```
4343
## 第三步,使用说明

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.text.style.LeadingMarginSpan;
1515
import android.util.AttributeSet;
1616
import android.util.LayoutDirection;
17+
import android.util.Log;
1718

1819
import androidx.core.text.TextUtilsCompat;
1920

@@ -127,13 +128,11 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
127128

128129
@Override
129130
protected void onDraw(Canvas canvas) {
130-
ColorStateList textColor = getTextColors();
131131
TextPaint textPaint = getPaint();
132132
Paint.Style oldStyle = textPaint.getStyle();
133133
textPaint.setStrokeWidth(strokeWidth);
134134
textPaint.setStyle(Paint.Style.FILL_AND_STROKE);
135135
textPaint.setStrokeJoin(strokeJoin);
136-
setTextColor(strokeTextColor);
137136
if (gradientStrokeColor){
138137
float currentAngle = strokeAngle;
139138
if (strokeRtlAngle && isRtl){
@@ -144,13 +143,11 @@ protected void onDraw(Canvas canvas) {
144143
@SuppressLint("DrawAllocation") LinearGradient linearGradient = new LinearGradient(xy[0], xy[1], xy[2], xy[3], gradientStrokeColors, gradientStrokePositions, Shader.TileMode.CLAMP);
145144
textPaint.setShader(linearGradient);
146145
}else {
147-
textPaint.setShader(null);
146+
@SuppressLint("DrawAllocation") LinearGradient linearGradient = new LinearGradient(0, 0,getWidth(),getHeight(), new int[]{strokeTextColor,strokeTextColor}, null, Shader.TileMode.CLAMP);
147+
textPaint.setShader(linearGradient);
148148
}
149149
super.onDraw(canvas);
150150
textPaint.setStrokeWidth(0);
151-
if (textColor != null){
152-
setTextColor(textColor);
153-
}
154151
textPaint.setStyle(oldStyle);
155152
if (gradientColor){
156153
float currentAngle = angle;

0 commit comments

Comments
 (0)