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

相关推荐
booboosui2 分钟前
安卓 8.1 也能装了:代价是一条黄字和两个静默 bug
android
Ehtan_Zheng3 小时前
Jetpack AppState Transform:让 Compose 的响应式状态走出 UI 层
android
OriginCoding3 小时前
一个 JDK 跑起六个分布式挑战:Kotlin 版 Gossip Glomers(一)
分布式·kotlin
yyuuuzz5 小时前
nginx 502 排查,先看上游超时那一行
android·java·运维·nginx·502
恋猫de小郭9 小时前
Flutter 3.50.0 Release 的第一个崩溃,修好了,还没 hotfix
android·前端·flutter
alexhilton19 小时前
MVI 让屏幕一次只有一个状态
android·kotlin·android jetpack
二流小码农1 天前
鸿蒙开发:证书只能创建3个,第4个应用怎么办
android·ios·harmonyos
阿杰m1 天前
Android源码第十七章:PowerManager 与后台任务——锁屏后怎么跑?
android
JMchen1231 天前
【Android 性能优化实战 60 讲】10 Jetpack App Startup 内核魔改:手写异步懒加载启动框架,根治串行初始化耗时
android·性能优化·源码分析·启动优化·kotlin协程·app startup
2601_967980111 天前
python+appium自动化测试如何控制App的启动和退出
android·自动化测试·python·appium·设备调试