机器人 - 获取视图的可见区域?视图、机器人、区域

2023-09-06 07:50:22 作者:裸奔的小猪~

假设我有一个Android 查看正在被部分地被另一个屏蔽查看。举例来说,假设屏蔽观点有它的中心一个透明的矩形窗口,而我的观点是围绕窗口,并具有尺寸大于窗口的尺寸较大的下方。在这种情况下,视图的一些矩形部分将可见,其余被遮盖的掩模。

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

我打过电话 getLocalVisibleRect(),听起来很有希望,但似乎只返回该视图的布局矩形和的不是的的是矩形实际上可见。

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.

推荐答案

这是pretty的后来者,但我怀疑 getGlobalVisibleRect 你想要做什么

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