Android 测量文本宽度方式
Android 测量文本宽度方式
val str = "hello world"
val paint = TextPaint()
paintEnd.textSize = xxx
paintEnd.typeface = xxx
1.measureText
🍎 该方式会受到 文字大小(textSize)
和 字体(typeface)
的影响
paint.measureText(str)
2. getTextBounds
val rect = Rect()
paint.getTextBounds(str, 0, str.length, rect)
val w: Int = rect.width()
3. getDesiredWidth
android.text.Layout.getDesiredWidth(str, paint)
解决 ClickableSpan 和 ForegroundColorSpan 颜色冲突问题
val clickableSpan: ClickableSpan = object : ClickableSpan() {
override fun onClick(widget: View?) {
}
override fun updateDrawState(ds: TextPaint?) {
//super.updateDrawState(ds)
//ds?.color = ds?.linkColor //解决 ClickableSpan 和 ForegroundColorSpan 颜色冲突问题
ds?.isUnderlineText = false //去掉下划线
}
}
本文作者:风之旅人
本文链接:https://www.cnblogs.com/jooy/p/17302017.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。