Android - Understanding View.getLocalVisibleRect(Rect)

后端 未结 1 1210
孤独总比滥情好
孤独总比滥情好 2021-02-18 13:29

I\'m looking for any clue to understand this method.

There is no info in official Android\'s SDK documentation about it.

What kind of Rectangle does it return? <

相关标签:
1条回答
  • 2021-02-18 13:33

    From the 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 calls getGlobalVisibleRect and then makes it local as suggested:

    r.offset(-offset.x, -offset.y); // make r local`
    

    So:

    • It doesn't return a Rectangle, it returns a boolean. But it can set the parameters of a rectangle you pass, and that must be an android.graphics.Rect rectangle;
    • The rectangle r will be filled with local coordinates;
    • I'm not sure but I think it's the same for visibile and invisible views, while it should return false for views with visibility="gone"
    0 讨论(0)
提交回复
热议问题