How to check the visibility of a view? [SOLVED] – Android Studio

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

View.VISIBLE The view is visible.

View.INVISIBLE The view is invisible, but any spacing it would normally take up will still be used. Its “invisible”

View.GONE The view is gone, you can’t see it and it doesn’t take up the “spot”.

So to check whether the View is visible or not and then do something accordingly, you could use the following code:

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

References:
StackOverflow

[wpedon id="7041" align="center"]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.