Created
May 3, 2023 17:04
-
-
Save happysingh23828/a8d5268d18b4aa65e6bace8df55b3e8e to your computer and use it in GitHub Desktop.
View visible in Scrollview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun View.isPartiallyOrFullyVisible(horizontalScrollView: HorizontalScrollView) : Boolean { | |
val scrollBounds = Rect() | |
horizontalScrollView.getHitRect(scrollBounds) | |
return getLocalVisibleRect(scrollBounds) | |
} | |
fun View.isPartiallyOrFullyVisible(scrollView: ScrollView) : Boolean { | |
val scrollBounds = Rect() | |
scrollView.getHitRect(scrollBounds) | |
return getLocalVisibleRect(scrollBounds) | |
} | |
fun View.isFullyVisible(horizontalScrollView: HorizontalScrollView) : Boolean { | |
val scrollBounds = Rect() | |
horizontalScrollView.getDrawingRect(scrollBounds) | |
val left = x | |
val right = left + width | |
return scrollBounds.left < left && scrollBounds.right > right | |
} | |
fun View.isFullyVisible(scrollView: ScrollView) : Boolean { | |
val scrollBounds = Rect() | |
scrollView.getDrawingRect(scrollBounds) | |
val top = y | |
val bottom = top + height | |
return scrollBounds.top < top && scrollBounds.bottom > bottom | |
} | |
fun View.isPartiallyVisible(horizontalScrollView: HorizontalScrollView) : Boolean = isPartiallyOrFullyVisible(horizontalScrollView) && !isFullyVisible(horizontalScrollView) | |
fun View.isPartiallyVisible(scrollView: ScrollView) : Boolean = isPartiallyOrFullyVisible(scrollView) && !isFullyVisible(scrollView) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment