LoginSignup
1
0

More than 5 years have passed since last update.

MotionEventのgetYとgetRawYの違い

Posted at

概要

MotionEventgetYgetRawYを扱うことがあったのですが、若干取得できる値が違ったので調べてみました。

Android座標系

(調査中)

Androidにはいくつかの座標系があるみたいです。 「Android 座標系」で検索すると、いくつか記事が出てきますが公式のドキュメントには日本語ではひっかからないように思います。(キーワードが悪いだけ?)

Android開発のメモ: 座標系についてによると、Androidには以下の2つの座標系があります。

  • スクリーン座標系
  • ローカル座標系

blog7.jpg

出典: Android開発のメモ: 座標系について

本題

さて、問題のMotionEventの2つのメソッドを比較してみましょう。

MotionEvent#getY

getY(int) for the first pointer index (may be an arbitrary pointer identifier).

MotionEvent#getRawY

Returns the original raw Y coordinate of this event. For touch events on the screen, this is the original location of the event on the screen, before it had been adjusted for the containing window and views.

どうやら、 getY はローカル座標系を、 getRawY はスクリーン座標系を返すようです。ちなみに、ローカル座標系を親のローカル座標系に直す場合は、自分のLeftを加算してあげる必要があります。

宿題

  • Androidの座標系についてもう少し詳しく調べる
  • AndroidのPointer Index, Data Indexについて調べる

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0