Android着色器SweepGradient渐变圆环,Kotlin

Android着色器SweepGradient渐变圆环,Kotlin

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.AppCompatImageView


class MyView : AppCompatImageView {
    private var mPaint: Paint? = null
    private var mPath: Path? = null
    private var mSweepGradient: SweepGradient? = null

    constructor(ctx: Context, attributeSet: AttributeSet) : super(ctx, attributeSet) {
        val W = resources.displayMetrics.widthPixels
        val H = resources.displayMetrics.heightPixels

        mPaint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG)
        mPaint?.style = Paint.Style.STROKE
        mPaint?.strokeWidth = 60f

        mPath = 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

相关推荐
simplepeng3 小时前
我的天,我真是和androidx的字体加载杠上了
android
小猫猫猫◍˃ᵕ˂◍4 小时前
备忘录模式:快速恢复原始数据
android·java·备忘录模式
CYRUS_STUDIO6 小时前
使用 AndroidNativeEmu 调用 JNI 函数
android·逆向·汇编语言
梦否6 小时前
【Android】类加载器&热修复-随记
android
徒步青云6 小时前
Java内存模型
android
今阳6 小时前
鸿蒙开发笔记-6-装饰器之@Require装饰器,@Reusable装饰器
android·app·harmonyos
-优势在我11 小时前
Android TabLayout 实现随意控制item之间的间距
android·java·ui
hedalei11 小时前
android13修改系统Launcher不跟随重力感应旋转
android·launcher
Indoraptor13 小时前
Android Fence 同步框架
android
峥嵘life13 小时前
DeepSeek本地搭建 和 Android
android