How to check if a view is visible in a certain area or not inside ScrollView

I have one ScrollView inside my application, this ScrollView contains the number of images in it, we have to scroll down to view each image, because the scrollview area is larger than the screen size.

Now the question arises: how can I verify that each ScrollView image is inside a certain area (defined by me) or not.

If the image is inside this area, I want to do something, but if not, then I want to do something else.

Please help me out of the problem, any help will be noticeable.

Thanks.

+4
source share
2 answers

See below code. Check if this works.

public static boolean isInVisible(ScrollView scrollView, View view, Rect region, boolean relative) { int top = scrollView.getScrollY() + region.top; int bottom = scrollView.getScrollY() + region.bottom; if(!relative) { // If given region is not relative to scrollView // ie 0,0 does not point to first child left and top top -= scrollView.getTop(); bottom -= scrollView.getTop(); } Rect rect = new Rect(region); rect.top = top; rect.bottom = bottom; Rect childRegion = new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom()); return Rect.intersects(childRegion, region); } 
+2
source

yes, each image in the ScrollView window is determined by you. In addition, you modify any changes within your scroll. If you have any specific need, send your code

0
source

Source: https://habr.com/ru/post/1482318/


All Articles