java - 如何检查所有文本视图文本是否在滚动视图中可见
问题描述
我尝试检查文本的高度textview
是否大于scroll
视图以处理用户不必滚动阅读文本但在线没有任何内容对我有用的情况。
我在网上尝试了解决方案,但那些也不起作用
if (binding.wvTermsAndCond.getLocalVisibleRect(scrollBounds)) {
// imageView is within the visible window
Utils.showToast(mContext, "View is within the visible window", true);
} else {
// imageView is not within the visible window
Utils.showToast(mContext, "View is not within the visible window", true);
}
不可见的块被调用
解决方案
如果要检查视图是否可见,可以使用以下方法:
public static boolean isVisible(final View view) {
if (view == null) {
return false;
}
if (!view.isShown()) {
return false;
}
final Rect actualPosition = new Rect();
view.getGlobalVisibleRect(actualPosition);
final Rect screen = new Rect(0, 0, getScreenWidth(), getScreenHeight());
return actualPosition.intersect(screen);
}
public static int getScreenWidth() {
return Resources.getSystem().getDisplayMetrics().widthPixels;
}
public static int getScreenHeight() {
return Resources.getSystem().getDisplayMetrics().heightPixels;
}
推荐阅读
- c# - 如何使用 Entity Framework 6 配置 DbContext
- reactjs - webpack-cli 不能同时运行多个命令
- linux - Ubuntu 20.04 交叉编译使用 yocto jethro 无效 gcc 搜索路径
- php - MySQL查询多个ID
- similarity - 计算对象“相似性指纹”
- javascript - TypeError: makeUser 不是函数 discord js V12
- sql - 以 pdf 格式导出 SSRS 报告存在空白页问题
- php - 为什么 index.php 中的 PHP 代码会执行多次?(.htaccess)
- php - 未找到 InvalidArgumentException 视图 [back.admin]
- xml - 有没有办法在 XML 中包含类似标签的文本?