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

相关推荐
游戏开发爱好者87 分钟前
HTTPS 内容抓取实战 能抓到什么、怎么抓、不可解密时如何定位(面向开发与 iOS 真机排查)
android·网络协议·ios·小程序·https·uni-app·iphone
Tom4i2 小时前
Android 系统的进程模型
android
介一安全2 小时前
【Frida Android】基础篇9:Java层Hook基础——Hook构造函数
android·网络安全·逆向·安全性测试·frida
杨筱毅2 小时前
【Android】Compose绘制系统 VS 传统View绘制系统
android
介一安全2 小时前
【Frida Android】基础篇10:Native层Hook基础--普通 Hook
android·网络安全·逆向·安全性测试·frida
位步4 小时前
在linux系统中使用通用包安装 Mysql
android·linux·mysql
生莫甲鲁浪戴4 小时前
Android Studio新手开发第二十六天
android·前端·android studio
sky0Lan5 小时前
一个类似 pytest 的 html 报告
android·html·pytest
怪兽20146 小时前
Handler中有Loop死循环,为什么没有阻塞主线程,原理是什么?
android·面试
雨白6 小时前
掌握协程的边界与环境:CoroutineScope 与 CoroutineContext
android·kotlin