I have defined the custom drawable below:
class HexDrawable constructor(val text: String) : Drawable() {
private val paint = Paint()
init {
paint.color = Color.WHITE
paint.textSize = 22f
paint.isAntiAlias = true
paint.isFakeBoldText = true
paint.setShadowLayer(3f, 0f, 0f, Color.BLACK)
paint.style = Paint.Style.FILL
}
override fun draw(canvas: Canvas) {
val width: Int = 120
val height: Int = 120
val radius: Float = Math.min(width, height).toFloat() / 2f
// Draw a green circle in the center
canvas.drawCircle((width / 2).toFloat(), (height / 2).toFloat(), radius, paint)
}
override fun setAlpha(alpha: Int) {
paint.alpha = alpha
}
override fun setColorFilter(colorFilter: ColorFilter?) {
paint.colorFilter = colorFilter
}
override fun getOpacity(): Int {
return PixelFormat.OPAQUE
}
}
I am not sure what units the drawable is using. I want to use eg 40dp
for the width but the 120 that is specified in the code above turns out very small when it is drawn on the screen so I donlt think it is dp
, maybe it is mm
?
can someone please clarify what unit it is using by default? and how to use dp instead?