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

I'm a physicist specializing in theoretical, computational and experimental condensed matter physics. I like to develop Physics related apps and softwares from time to time. Can code in most of the popular languages. Like to share my knowledge in Physics and applications using this Blog and a YouTube channel.



Leave a Reply

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