我正在寻找任何线索来理解这种方法。Android - 理解View.getLocalVisibleRect(Rect)
在official Android's SDK documentation没有关于它的信息。
它返回什么样的矩形?
它是否充满了像MotionEvent这样的Raw coorinates?
如果此视图不可见,该怎么办?它是否返回null?或者是一些带有某种VIEW_INVISIBLE值的矩形?
有没有使用这种方法的经验的人能帮我一把吗?
我正在寻找任何线索来理解这种方法。Android - 理解View.getLocalVisibleRect(Rect)
在official Android's SDK documentation没有关于它的信息。
它返回什么样的矩形?
它是否充满了像MotionEvent这样的Raw coorinates?
如果此视图不可见,该怎么办?它是否返回null?或者是一些带有某种VIEW_INVISIBLE值的矩形?
有没有使用这种方法的经验的人能帮我一把吗?
从JavaDoc of getGlobalVisibleRect:
/**
* If some part of this view is not clipped by any of its parents, then
* return that area in r in global (root) coordinates. To convert r to local
* coordinates (without taking possible View rotations into account), offset
* it by -globalOffset (e.g. r.offset(-globalOffset.x, -globalOffset.y)).
* If the view is completely clipped or translated out, return false.
*
* @param r If true is returned, r holds the global coordinates of the
* visible portion of this view.
* @param globalOffset If true is returned, globalOffset holds the dx,dy
* between this view and its root. globalOffet may be null.
* @return true if r is non-empty (i.e. part of the view is visible at the
* root level.
*/
getLocalVisibleRect调用getGlobalVisibleRect然后使得当地的建议:
r.offset(-offset.x, -offset.y); // make r local`
所以:
visibility="gone"
非常感谢您的回答。也许,Android源代码中有更多有关此方法的答案。 – UnknownJoe
通常在Android中阅读源代码是尝试弄清楚发生了什么的最好的第一步。 –
我创建了一个问题的文件。您可以在这里跟踪https://issuetracker.google.com/issues/73832083 顺便说一句,如果您发现缺少或不适当的东西,您也可以为文档创建问题。在页面的最底部有'support'部分。在那里你可以选择“报告文档错误”。 –