How can I check if a view is visible or not in Android?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In Android, "visible" can mean at least three different things. A view can be marked VISIBLE in the layout, it can be effectively shown after considering its parents, or it can be physically on screen inside the current viewport. The right API depends on which of those meanings you actually need.
Check the Basic Visibility Flag
The simplest check is whether the view’s own visibility property is set to View.VISIBLE.
This answers only one narrow question: what is the view’s configured visibility state. It does not tell you whether the parent is hidden, whether the view is attached, or whether the user can see it on screen.
The three possible values are:
- '
View.VISIBLE' - '
View.INVISIBLE' - '
View.GONE'
INVISIBLE keeps the view in the layout but does not draw it. GONE removes it from the layout flow entirely.
Use isShown for a Better High-Level Check
If you want to know whether the view and its ancestors are all visible, isShown is a stronger signal.
This is often the right answer for business logic such as "should I attempt to interact with this widget right now?" It still is not a perfect viewport check, but it is better than reading only visibility.
Check Actual On-Screen Visibility
For analytics, lazy loading, autoplay rules, or impression tracking, you usually care about whether any part of the view is currently visible on screen. getGlobalVisibleRect is the most common tool for that.
This method considers clipping and screen position. It gives a much better signal for "can the user actually see some part of this view right now?"
If you need a reusable helper, wrap the rule:
That version avoids false positives from views that are technically shown but not attached or not occupying a visible region.
RecyclerView and Scroll Containers Need Extra Care
A child view inside RecyclerView, NestedScrollView, or another scrolling container can be perfectly valid and still not be visible in the viewport. In those cases, plain visibility flags are usually not enough.
Sometimes it is easier to ask the layout manager instead of the view:
That is often a better fit when your question is really about item positions rather than one specific child view instance.
Attachment and Layout Timing Matter
Visibility checks can be misleading if the view has not been attached or laid out yet. Early in onCreate, for example, the view tree may exist but not have final bounds.
If you need dimensions or screen location, run the check after layout by using post {} or a layout listener.
Common Pitfalls
One common mistake is treating visibility == View.VISIBLE as proof that the user can see the view. That only checks the local visibility flag.
Another mistake is forgetting parent visibility. A child can be VISIBLE while a parent container is hidden, which is why isShown often gives a more useful answer.
Developers also sometimes run viewport checks before the view is attached or measured. In that state, geometry-based methods can give confusing results.
Finally, for list screens, do not overcomplicate the problem by checking every child manually when the layout manager already exposes visible item ranges.
Summary
- '
visibility == View.VISIBLEchecks only the view’s own flag.' - '
isShownalso accounts for ancestor visibility.' - '
getGlobalVisibleRectis the better choice for actual on-screen visibility.' - Attachment and layout timing affect whether visibility checks are meaningful.
- In scrolling containers, layout-manager APIs are often more useful than raw child-view checks.

