Fix text drawable icon scaling
This commit is contained in:
@@ -7,7 +7,8 @@ import android.graphics.drawable.Drawable
|
||||
class TextDrawable(
|
||||
val text: String,
|
||||
val color: Int = Color.WHITE,
|
||||
fontSize: Float = 13f,
|
||||
val height: Int? = null,
|
||||
val fontSize: Float = 13f,
|
||||
typeface: Typeface = Typeface.DEFAULT
|
||||
): Drawable() {
|
||||
|
||||
@@ -25,6 +26,8 @@ class TextDrawable(
|
||||
|
||||
override fun draw(canvas: Canvas) {
|
||||
val bounds = bounds
|
||||
if (height != null) paint.textSize = fontSize * bounds.height().toFloat() / height.toFloat()
|
||||
else paint.textSize = fontSize
|
||||
paint.getTextBounds(text, 0, text.length, rect)
|
||||
canvas.drawText(text, bounds.exactCenterX(), bounds.exactCenterY() + rect.height() / 2f, paint)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user