blakelee
07/30/2017, 9:58 PMfun 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: