Skip to content

Commit

Permalink
优化防止过度绘制
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyJingFish committed May 15, 2023
1 parent fe0c2fa commit d6ecd64
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

```gradle
dependencies {
implementation 'com.github.FlyJingFish:GradientTextView:1.1.1'
implementation 'com.github.FlyJingFish:GradientTextView:1.1.2'
}
```
## 第三步,使用说明
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.text.style.LeadingMarginSpan;
import android.util.AttributeSet;
import android.util.LayoutDirection;
import android.util.Log;

import androidx.core.text.TextUtilsCompat;

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

@Override
protected void onDraw(Canvas canvas) {
ColorStateList textColor = getTextColors();
TextPaint textPaint = getPaint();
Paint.Style oldStyle = textPaint.getStyle();
textPaint.setStrokeWidth(strokeWidth);
textPaint.setStyle(Paint.Style.FILL_AND_STROKE);
textPaint.setStrokeJoin(strokeJoin);
setTextColor(strokeTextColor);
if (gradientStrokeColor){
float currentAngle = strokeAngle;
if (strokeRtlAngle && isRtl){
Expand All @@ -144,13 +143,11 @@ protected void onDraw(Canvas canvas) {
@SuppressLint("DrawAllocation") LinearGradient linearGradient = new LinearGradient(xy[0], xy[1], xy[2], xy[3], gradientStrokeColors, gradientStrokePositions, Shader.TileMode.CLAMP);
textPaint.setShader(linearGradient);
}else {
textPaint.setShader(null);
@SuppressLint("DrawAllocation") LinearGradient linearGradient = new LinearGradient(0, 0,getWidth(),getHeight(), new int[]{strokeTextColor,strokeTextColor}, null, Shader.TileMode.CLAMP);
textPaint.setShader(linearGradient);
}
super.onDraw(canvas);
textPaint.setStrokeWidth(0);
if (textColor != null){
setTextColor(textColor);
}
textPaint.setStyle(oldStyle);
if (gradientColor){
float currentAngle = angle;
Expand Down

0 comments on commit d6ecd64

Please sign in to comment.