Skip to content

Instantly share code, notes, and snippets.

@teshi04
Last active April 10, 2019 07:02
Show Gist options
  • Save teshi04/b8172467e4fdc63ed4f3a7feeea3225f to your computer and use it in GitHub Desktop.
Save teshi04/b8172467e4fdc63ed4f3a7feeea3225f to your computer and use it in GitHub Desktop.
package jp.tsur.android
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.RectF
import android.util.AttributeSet
import android.view.View
class DrawRectView(context: Context?, attrs: AttributeSet?) : View(context, attrs) {
private val paint: Paint = Paint(Paint.ANTI_ALIAS_FLAG)
private var rect: RectF? = null
init {
paint.color = Color.GREEN
paint.strokeWidth = 10f
}
override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)
val rect1 = rect
rect1 ?: return
canvas?.drawRect(rect1.left, rect1.top, rect1.right, rect1.bottom, paint)
}
fun draw(rect: RectF) {
this.rect = rect
postInvalidate()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment