Advertisement
lituchy

Untitled

Feb 11th, 2020
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.73 KB | None | 0 0
  1.     var s = "${text.subSequence(0, position)} ${text.subSequence(position, text.length)}"
  2.     val rect = Rect()
  3.     var measureText = paint.measureText(s.toString())
  4.     val availableWidth = measuredWidth - totalPaddingStart - paint.measureText(" ")
  5.     var count = 0
  6.     var arry = FloatArray(s.length)
  7.     while(arry.sum() < availableWidth) {
  8.         s = "${s.subSequence(0, position)} ${s.subSequence(position, s.length)}"
  9.         measureText = paint.measureText(s)
  10.         paint.getTextBounds(s, 0, s.length, rect)
  11.         arry = FloatArray(s.length)
  12.         paint.getTextWidths(s, arry)
  13.         count++
  14.     }
  15.     Timber.d(count.toString())
  16.     text = "${s.subSequence(0, position)}${s.subSequence(position + 1, s.length)}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement