24

この方法を理解するための手がかりを探しています。

Androidの公式SDKドキュメントにはそれに関する情報はありません。

どんな長方形が返ってきますか?

MotionEventのようにRawcoorinateでいっぱいですか?

このビューが表示されていない場合はどうなりますか?nullを返しますか?または、ある種のVIEW_INVISIBLE値が内部にある長方形ですか?

この方法を使った経験のある人は誰でも私に手を差し伸べることができますか?

4

1 に答える 1

24

getGlobalVisibleRectJavaDocから:

/**
 * 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`

それで:

  • 長方形を返すのではなく、ブール値を返します。ただし、渡す長方形のパラメーターを設定できます。これはandroid.graphics.Rect長方形である必要があります。
  • 長方形rはローカル座標で埋められます。
  • よくわかりませんが、表示されているビューと表示されていないビューの場合は同じだと思いますが、visibility="gone"
于 2013-08-18T19:12:58.243 に答える