Created
February 14, 2022 14:24
-
-
Save mikkipastel/2b418558879eef047309a03e39a6ed0b to your computer and use it in GitHub Desktop.
try to draw segment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import android.graphics.* | |
import android.util.AttributeSet | |
import android.view.View | |
class SegmentCircleView @JvmOverloads constructor( | |
context: Context, | |
attrs: AttributeSet? = null, | |
defStyleAttr: Int = 0 | |
) : View(context, attrs, defStyleAttr) { | |
private val paintSource = Paint().apply { | |
isAntiAlias = true | |
color = Color.RED | |
style = Paint.Style.FILL | |
} | |
private val paintDestination = Paint().apply { | |
isAntiAlias = true | |
color = Color.YELLOW | |
style = Paint.Style.FILL | |
xfermode = PorterDuffXfermode(PorterDuff.Mode.ADD) | |
} | |
override fun onDraw(canvas: Canvas?) { | |
super.onDraw(canvas) | |
val cx = 200f | |
val cy = 200f | |
val radius = 100f | |
canvas?.drawCircle( | |
cx, | |
cy, | |
radius, | |
paintSource | |
) | |
val left = 100f | |
val top = 240f | |
val right = 300f | |
val bottom = 300f | |
val rectF = RectF( | |
left, | |
top, | |
right, | |
bottom, | |
) | |
canvas?.drawRect(rectF, paintDestination) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment