Android - 获取视图的可见区域?
假设我有一个Android View
,被另一个View
部分掩盖。例如,假设遮罩视图的中央有一个透明的矩形“窗口”,而且我的视图位于窗口下方,并且尺寸大于窗口的尺寸。在这种情况下,视图中的某些矩形部分将可见,其余部分将被遮罩遮挡。Android - 获取视图的可见区域?
所以我的问题是,是否有以检索可见区域的位置和尺寸,而无需掩蔽视图本身的任何访问任何直接的方式(所以不知道自己是蒙版的“窗口”有多大)?
我打过电话getLocalVisibleRect()
,听起来很有希望,但似乎只返回该视图的布局矩形和不,实际上是可见的矩形。
这难道不是工作:http://developer.android.com/reference/android/view/View.html#getDrawingRect(android.graphics.Rect)
文档说,这你想要做什么。
不,它给出了与调用getWidth()和getHeight()(即总视图大小)相同的结果。正如文档所述,'getDrawingRect()'“用'getScrollX()','getScrollY()','getWidth()'和'getHeight()'”填充输出矩形。在这种情况下,'scrollX'和'scrollY'值将为0,因为没有滚动进行。 – aroth 2012-01-31 05:42:24
我已经使用getWindowVisibleDisplayFrame
方法来确定视图是否部分可见或不能确定软键盘是否打开。你可以试试看。
Rect r = new Rect();
// r will be populated with the coordinates of your view
// that area still visible.
rootView.getWindowVisibleDisplayFrame(r);
为此得到了什么解决方案?有相同的问题.. – user936414 2013-01-22 06:37:31
似乎重复(但没有答案):http://stackoverflow.com/questions/34724179/how-to-find-whether-an-android-view-is-obscured-by-any-other -view – 2016-07-06 21:46:49
有没有想过这个? – Nima 2017-07-06 19:14:54