のカスタムビュー内のタッチイベントに応答しますonTouchEvent(MotionEvent event)
。座標の不一致に問題がありevent.getRaw(Y)
ます。ステータスバーを含むタッチのY座標をmyView.getTop()
返しますが、ステータスバーを除くビューの上部のY座標を返します。ステータスバーの高さを修正するために、次のハックに頼りました。
// Get the size of the visible window (which excludes the status bar)
Rect rect = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
// Get the coordinates of the touch event, subtracting the top margin
final int x = (int) event.getRawX();
final int y = (int) event.getRawY() - rect.top;
より良い解決策はありますか?