MotionEventのgetYとgetRawYの違い
概要
MotionEventでgetY
と getRawY
を扱うことがあったのですが、若干取得できる値が違ったので調べてみました。
Android座標系
(調査中)
Androidにはいくつかの座標系があるみたいです。 「Android 座標系
」で検索すると、いくつか記事が出てきますが公式のドキュメントには日本語ではひっかからないように思います。(キーワードが悪いだけ?)
Android開発のメモ: 座標系についてによると、Androidには以下の2つの座標系があります。
- スクリーン座標系
- ローカル座標系
本題
さて、問題のMotionEventの2つのメソッドを比較してみましょう。
getY(int) for the first pointer index (may be an arbitrary pointer identifier).
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について調べる
参考
Author And Source
この問題について(MotionEventのgetYとgetRawYの違い), 我々は、より多くの情報をここで見つけました https://qiita.com/rindo/items/cdc966d668b39cc1ec82著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .