I want to know when a view of my layout is showing in physical screen. You know in some apps that uses ScrollView, you must scroll down to see other views. I want to know when a view like Button or TextView or another view is showing in physical screen to do some job. Thanks in advance:)
-
Possible duplicate of Android: how to check if a View inside of ScrollView is visible? – Amagi82 Nov 23 '16 at 20:39
Try this:
Rect scrollBounds = new Rect();
scrollView.getHitRect(scrollBounds);
if (view.getLocalVisibleRect(scrollBounds)) {
// Any portion of the view, even a single pixel, is within the visible window
} else {
// NONE of the view is within the visible window
}
-
thanks. it worked. i have another question, can i ask it here? it is sequence of this question. – karimkhan Jul 10 '15 at 13:05
-
1
-
yes sure. I have six gridview in my layout. And i want to load images in them when user see them in physical screen. How can i do that with your answer? – karimkhan Jul 10 '15 at 13:09
-
@karimkhan, then you don't need my Answer. Just use a Picasso or UniversalImageLoader. In your adapter method, when you inflating items, find your imageview and do this(for picasso):
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);Here is link to picasso: square.github.io/picasso – Alexander Jul 10 '15 at 13:12 -
1