karimkhan
karimkhan

Reputation: 329

How to know a view is showing in physical screen or not?

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

Upvotes: 2

Views: 1816

Answers (1)

Aleksandr
Aleksandr

Reputation: 4936

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
}

Upvotes: 3

Related Questions