看了很多文章,获取View在屏幕中是否可见总结如下:
判断部分可见:
var isVisible=view.getLocalVisibleRect(Rect())
判断是否完全可见:
fun isTotallyVisible(view: View): Boolean {
var rect = Rect()
var visible = view.getLocalVisibleRect(rect)
if (!visible || (rect.bottom - rect.top) * (rect.right - rect.left) < view.width * view.height) {
return false
}
return true
}