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:)

up vote 3 down vote accepted

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
    @karimkhan, Yes, you may. If my answer is correct, accept it please – Alexander Jul 10 '15 at 13:05
  • 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
    thanks. worked fine. – karimkhan Jul 10 '15 at 14:26

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.