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

相关推荐
大白菜和MySQL11 小时前
linux系统环境常用命令
android·linux·adb
Ehtan_Zheng11 小时前
彻底告别 AndroidX 依赖:如何在 KMP 中构建 100% 复用的 UI 逻辑层?
android
Hello小赵11 小时前
C语言如何自定义链接库——编译与调用
android·java·c语言
IT枫斗者12 小时前
构建具有执行功能的 AI Agent:基于工作记忆的任务规划与元认知监控架构
android·前端·vue.js·spring boot·后端·架构
用户693717500138412 小时前
XChat 为什么选择 Rust 语言开发
android·前端·ios
林栩link12 小时前
【车载 Android】实践跨进程 UI 融合渲染
android
Paxon Zhang12 小时前
MySQL 大师之路**数据库约束,表设计,CRUD**
android·数据库·mysql
Indoraptor13 小时前
SurfaceFinger FrameTimeline 分析
android·源码阅读
zh_xuan13 小时前
Android 待办事项增加事项统计
android
zopple13 小时前
Laravel 10.x新特性全解析
android