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

相关推荐
HLC++2 小时前
Linux的进程间通信
android·linux·服务器
爱笑鱼5 小时前
Binder(二):AIDL 生成的 Proxy、Stub 和 Parcel 到底在做什么?
android
爱笑鱼6 小时前
Binder(一):一次方法调用,究竟怎样跨进程执行?
android
btown6 小时前
Kotlin 版 MyBatis-Plus 查询优雅解决方案
kotlin
壮哥_icon7 小时前
【Android 系统开发】使用 BAT 脚本高效自动化管理 /system/priv-app/ 系统应用(安装与卸载)
android·运维·自动化
用户69371750013848 小时前
Claude Code终端日志Token占用实测:一个过滤器砍掉60%-90%
android·前端·后端
蝉蜕日记8 小时前
AccumuPDF高级版 v2.57 | 视图文转换PDF,合并分割压缩
android·智能手机·pdf·生活·软件需求
吐了啊取名字太难8 小时前
美颜系统AI修图本地跑并支持Mac、win、安卓、iOS不卡顿
android·人工智能·windows·数码相机·mac·ai编程
小二·9 小时前
车载数字座舱实战:用魔珐星云打造下一代智能驾乘助手(附 Android/Kotlin 完整代码)
开发语言·kotlin
阿pin10 小时前
Android随笔-Retrofit
android·retrofit