I am trying to resize a spinner based on the textW...
# android
b
I am trying to resize a spinner based on the textWidth of the item clicked. I am using this code
Copy code
fun textWidth(text: String, context: Context): Int {
    val bounds = Rect()
    val textPaint = Paint()
    textPaint.textSize = 31f
    textPaint.getTextBounds(text, 0, text.length, bounds)
    return bounds.width() * (context.resources.displayMetrics.density + 0.5f).toInt()
}
When testing on emulator it shows this: