Last active
April 10, 2019 07:02
-
-
Save teshi04/b8172467e4fdc63ed4f3a7feeea3225f to your computer and use it in GitHub Desktop.
This file contains 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
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