如何计算textview可以处理多少个字符(kotlin)

ao218c7q  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(239)

我有很长的文本,我想以页面的形式查看,因此,我有一个文本视图,它可以覆盖整个屏幕,用户可以更改大小,因此,毕竟,我需要计算文本视图处理的字符数。
我想得到文本视图区域(宽度高度),并用文本大小进行划分。
如下所示:charscont=(宽度
高度)/textsize我的代码:

val textView: TextView = findViewById(R.id.textView)

textView.measure(0, 0)
// get textView width
val textViewWidth = textView.measuredWidth
// get textView Height
val textViewHeight = textView.measuredHeight
// get textView textSize
val textSize = textView.textSize
// getChars count
val charsCount = ((textViewWidth * textViewHeight) / textSize).toInt()

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题