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

相关推荐
液态不合群19 分钟前
【面试题】MySQL 中 count(*)、count(1) 和 count(字段名) 有什么区别?
android·数据库·mysql
雪球Snowball2 小时前
【Android关键流程】资源加载
android
2501_915918412 小时前
常见 iOS 抓包工具的使用,从代理抓包、设备抓包到数据流抓包
android·ios·小程序·https·uni-app·iphone·webview
灯火不休ᝰ3 小时前
[kotlin] 从Java到Kotlin:掌握基础语法差异的跃迁指南
java·kotlin·安卓
墨月白3 小时前
[QT]QProcess的相关使用
android·开发语言·qt
enbug4 小时前
编译安卓内核:以坚果R1、魔趣MK100(Android 10)系统为例
android·linux
、BeYourself4 小时前
应用专属文件与应用偏好设置(SharedPreferences)
android
2501_948120154 小时前
基于模糊数学的风险评估模型
android
MengFly_4 小时前
Compose 脚手架 Scaffold 完全指南
android·java·数据库
·云扬·5 小时前
MySQL Binlog三种记录格式详解
android·数据库·mysql