android - 安卓。文本视图。文本的最后一个可见字符
问题描述
我有一个针对整个屏幕的 TextView 匹配,并在其上附加了一个文本。例如,乌鸦诗:
Once upon a midnight dreary, while I pondered, weak and weary,
Over many a quaint and curious volume of forgotten lore,
While I nodded, nearly napping, suddenly there came a tapping,
As of some one gently rapping, rapping at my chamber door.
"'Tis some visiter," I muttered, "tapping at my chamber door—
Only this, and nothing more." etc etc etc...
我无法在手机屏幕上看到所有内容。所以问题是:如何获得文本最后一个可见字符的索引? 我怎么能看到它
解决方案
非常感谢Mike M这里的答案:
fun TextView.getLastVisibleCharacter(): Int {
val layoutBottom = height + scrollY - totalPaddingTop - totalPaddingBottom
val bottomLine = layout.getLineForVertical(layoutBottom)
val lastWhollyVisibleLineNumber =
if (layout.getLineBottom(bottomLine) > layoutBottom) bottomLine - 1
else bottomLine
return layout.getLineVisibleEnd(lastWhollyVisibleLineNumber) - 1
}
推荐阅读
- select - InlineCreateOperation with select 2 from ajax
- jenkins - 在脚本化管道的输入步骤中使用在 If 语句内分配的变量的值
- python-3.x - python 3 - 初学者问题 if/else Q 有错误
- azure-active-directory - Microsoft Graph 发送邮件功能已开始间歇性返回 200 状态
- amazon-web-services - Amazon Sagemaker:编写您自己的推理
- node.js - 由于 Oracle NOSql 的更多 Open 连接导致 CPU 使用率高的问题
- reactjs - 如何在 React 中 2 秒内隐藏元素
- google-chrome-extension - Chrome 扩展(从后台到其他 js 的消息):无法建立连接。接收端不存在
- javascript - 当另一个音频开始时停止播放音频
- plotly - Plotly 带有虚线或虚线边框的条形图 - 如何实现?