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:)
Asked
Active
Viewed 1,806 times
2

karimkhan
- 321
- 3
- 18
-
Possible duplicate of [Android: how to check if a View inside of ScrollView is visible?](http://stackoverflow.com/questions/4628800/android-how-to-check-if-a-view-inside-of-scrollview-is-visible) – Jim Pekarek Nov 23 '16 at 20:39
1 Answers
3
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
}

Aleksandr
- 4,906
- 4
- 32
- 47
-
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: http://square.github.io/picasso/ – Aleksandr Jul 10 '15 at 13:12
-
-
this is my adapter initializing method.http://s3.picofile.com/file/8199083734/123.PNG, and i load images from asset folder. – karimkhan Jul 10 '15 at 13:18
-
-
sorry [this is in gist.github.com](https://gist.github.com/anonymous/9c0c0b0580356263dcf4) – karimkhan Jul 10 '15 at 13:27
-
@karimkhan, I try this: https://gist.github.com/AlexanderGarmash/eb16e87c38bedfce252c – Aleksandr Jul 10 '15 at 13:32
-
-
@karimkhan, I have updated my gist file. I added `file:///android_asset/` – Aleksandr Jul 10 '15 at 13:35
-
-
@karimkhan, you don't need load bitmaps manually. This is very bad practice. You don't need care about showing bitmaps when they physical at screen. This will do Picasso. Just use this library and no problem will occured – Aleksandr Jul 10 '15 at 13:41
-
[this](https://gist.github.com/anonymous/4a65ba6de75709b65cd6) is my adapter initializing method. how can i change it to your way? – karimkhan Jul 10 '15 at 13:50
-
@karimkhan, checkout this: https://gist.github.com/AlexanderGarmash/eb16e87c38bedfce252c – Aleksandr Jul 10 '15 at 14:01
-
@karimkhan, I updated gist. Instead of `List
listWithImageNames` I added `Integer[] listWithImageNames`, and in `getView` use `listWithImageNames` instead `flagArray` – Aleksandr Jul 10 '15 at 14:02 -
Of course it will solve problem with OOM. Because your variant is absolutely wrong – Aleksandr Jul 10 '15 at 14:04
-
one question for me is that what i can use here Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView) instead of context inside gridviewadapter class. – karimkhan Jul 10 '15 at 14:11
-
@karimkhan, you should use `activity`. You defined it like: `private Activity activity;`. Use it instead context – Aleksandr Jul 10 '15 at 14:13
-
when i load images, there is a white background appear before image load in items of gridview. how can i insert a loading inside it before image load. – karimkhan Jul 10 '15 at 14:40
-
I must place Picasso.with(context) .load(url) .placeholder(R.drawable.user_placeholder) .error(R.drawable.user_placeholder_error) .into(imageView); inside gridviewadapter? – karimkhan Jul 10 '15 at 14:52
-
@karimkhan, yes instead `Picasso.with(context).load(listWithImageNames[position]).into(view.imgViewFlag);` – Aleksandr Jul 10 '15 at 14:56
-
i placed a gif load inside placehodler method but it is not loading. just show loading like a jpeg image constant – karimkhan Jul 10 '15 at 15:13
-