Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Get the visible area of a view?

Suppose I have an Android View that is being partially masked by another View. For instance, imagine that the masking view has a transparent rectangular "window" in the center of it, and my view is centered beneath the window and possessing dimensions that are larger than the dimensions of the window. In such a case, some rectangular portion of the view will be visible, with the rest being obscured by the mask.

So my question is, is there any straightforward way to retrive the position and dimensions of the visible area without having any access to the masking view itself (so without knowing how big the mask's "window" itself is)?

I tried calling getLocalVisibleRect(), which sounded promising, but that only seems to return the view's layout rectangle and not the rectangle that is actually visible.

like image 387
aroth Avatar asked Jan 31 '12 02:01

aroth


3 Answers

This is pretty late to the game, but I suspect that getGlobalVisibleRect does what you want.

like image 194
Abhay Buch Avatar answered Nov 14 '22 21:11

Abhay Buch


I have used getWindowVisibleDisplayFrame method to determine if view is partially visible or not to determine if a soft keyboard is open. You can try it out.

Rect r = new Rect();
// r will be populated with the coordinates of     your view
// that area still visible.
rootView.getWindowVisibleDisplayFrame(r);
like image 30
mou Avatar answered Nov 14 '22 23:11

mou


Does this not work: http://developer.android.com/reference/android/view/View.html#getDrawingRect(android.graphics.Rect)

The documentation says that it does what you want.

like image 40
Vikram Bodicherla Avatar answered Nov 14 '22 23:11

Vikram Bodicherla