判断View是否显示出现在屏幕上
fun isCoverScreen_LocalVisibleRect(view1: View): Boolean {
val screenWidth = CFUtil.getScreenWidth()//获取屏幕宽度
val screenHeight = CFUtil.getScreenHeight()//获取屏幕高度
val rect = Rect()
view1.getLocalVisibleRect(rect)
return !(rect.top<0||rect.bottom>screenHeight)
}
判断View可视区域占其自身百分比
fun getVisibilePercent(view1: View): Int {
val rect = Rect()
view1.getLocalVisibleRect(rect)
val a = rect.height() * 100 / view1.height
return a
}