How can I check if a view is visible or not in Android? [duplicate] How can I check if a view is visible or not in Android? [duplicate] android android

How can I check if a view is visible or not in Android? [duplicate]


Although View.getVisibility() does get the visibility, its not a simple true/false. A view can have its visibility set to one of three things.

View.VISIBLEThe view is visible.

View.INVISIBLEThe view is invisible, but any spacing it would normally take up will still be used. Its "invisible"

View.GONEThe view is gone, you can't see it and it doesn't take up the "spot".

So to answer your question, you're looking for:

if (myImageView.getVisibility() == View.VISIBLE) {    // Its visible} else {    // Either gone or invisible}


Or you could simply use

View.isShown()


If the image is part of the layout it might be "View.VISIBLE" but that doesn't mean it's within the confines of the visible screen. If that's what you're after; this will work:

Rect scrollBounds = new Rect();scrollView.getHitRect(scrollBounds);if (imageView.getLocalVisibleRect(scrollBounds)) {    // imageView is within the visible window} else {    // imageView is not within the visible window}