Android绘图Path基于LinearGradient线性渐变,Kotlin(1)
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.LinearGradient
import android.graphics.Paint
import android.graphics.Path
import android.graphics.Shader
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView
class MyView : AppCompatImageView {
private var mLinearGradient: LinearGradient? = null
private var mPaint: Paint? = null
private var mPath: Path? = null
private var mStartX = 0f
private var mStartY = 0f
private var mEndX = 0f
private var mEndY = 0f
constructor(ctx: Context, attributeSet: AttributeSet) : super(ctx, attributeSet) {
mPaint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG)
mPaint?.style = Paint.Style.STROKE
mPaint?.strokeWidth = 60f
mPath = Path()
}
private fun myUpdate() {
mStartX = 0f
mStartY = 0f
mEndX = width.toFloat()
mEndY = height.toFloat()
mPath?.moveTo(mStartX, mStartY)
mPath?.lineTo(mEndX, mEndY)
mLinearGradient =
LinearGradient(mStartX, mStartY, mEndX, mEndY, intArrayOf(Color.RED, Color.BLUE, Color.YELLOW), null, Shader.TileMode.CLAMP)
mPaint?.setShader(mLinearGradient)
}
override fun onDraw(canvas: Canvas) {
myUpdate()
canvas.drawPath(mPath!!, mPaint!!)
}
}
Android画布Canvas drawPath绘制跟随手指移动的圆,Kotlin_canvs.drawpath-CSDN博客文章浏览阅读1.1k次,点赞8次,收藏6次。文章浏览阅读2.3k次。Android SurfaceView简例Android中各的SurfaceView和View有很大的不同,两者应用场景不同。大多数View能做的事情SurfaceView也可以,但是SurfaceView效率更高。Android的View绘制过程由Android系统控制,刷新机制开发者比较难以控制。而SurfaceView支持高频、多线程绘制。SurfaceView不存在是否在Android U。Android SurfaceView简例-CSDN博客。_canvs.drawpathhttps://blog.csdn.net/zhangphil/article/details/135166305 从android.graphics.Path中取出Point点,Kotlin_android path 获取点-CSDN博客文章浏览阅读666次。本文介绍了如何使用Kotlin在Android中从`Path`对象中提取指定数量的`Point`点,以实现如涂鸦文字功能。作者提供了`getPoints`方法和`FloatPoint`类的示例,以及`PaintView`组件在实际应用中的使用。 https://blog.csdn.net/zhangphil/article/details/134442428