Android着色器SweepGradient渐变圆环,Kotlin
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import android.graphics.SweepGradient
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageViewclass MyView : AppCompatImageView {private var mPaint: Paint? = nullprivate var mPath: Path? = nullprivate var mSweepGradient: SweepGradient? = nullconstructor(ctx: Context, attributeSet: AttributeSet) : super(ctx, attributeSet) {val W = resources.displayMetrics.widthPixelsval H = resources.displayMetrics.heightPixelsmPaint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG)mPaint?.style = Paint.Style.STROKEmPaint?.strokeWidth = 60fmPath = Path()mPath?.addCircle(W / 2f, H / 2f, W / 3f, Path.Direction.CW)mSweepGradient =SweepGradient(W / 2f, H / 2f, intArrayOf(Color.TRANSPARENT, Color.RED, Color.BLUE, Color.YELLOW, Color.TRANSPARENT), null)mPaint?.setShader(mSweepGradient)}override fun onDraw(canvas: Canvas) {canvas.drawPath(mPath!!, mPaint!!)}
}
Android渲染器Shader:梯度渐变扫描渲染器SweepGradient(二)-CSDN博客文章浏览阅读4.5k次。Android渲染器Shader:梯度渐变扫描渲染器SweepGradient(二)附录文章1介绍了线性渐变渲染器。Android的SweepGradient梯度渐变扫描,重点是在构造SweepGradient的中心点选择。我写一个例子。package zhangphil.demo;import android.content.Context;import android_sweepgradienthttps://blog.csdn.net/zhangphil/article/details/52021677