---
title: "android中getX(),getY() 与getRawX(),getRawY()分析"
author: "JavaEEdyc"
date: "2014-12-09T12:13:14Z"
tags: []
categories: ["移动开发"]
slug: "android-getx-gety-getrawx-getrawy"
draft: false
lastmod: "2014-12-11T11:07:47Z"
id: 2164439
url: "https://javaeedyc.iteye.com/blog/2164439"
---

**先看getX(),getY()源码解释
 
```java
 /**
     * {@link #getX(int)} for the first pointer index (may be an
     * arbitrary pointer identifier).
     *
     * @see #AXIS_X
     */
    public final float getX() {
        return nativeGetAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
    }

    /**
     * {@link #getY(int)} for the first pointer index (may be an
     * arbitrary pointer identifier).
     *
     * @see #AXIS_Y
     */
    public final float getY() {
        return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
    }
```

**这个是相对于view的坐标距离**
**再看GetRawX(),getRawY()源码解释
 
```java
  /**
     * Returns the original raw X 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.
     *
     * @see getX()
     * @see #AXIS_X
     */
    public final float getRawX() {
        return nativeGetRawAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
    }

    /**
     * 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.
     *
     * @see getY()
     * @see #AXIS_Y
     */
    public final float getRawY() {
        return nativeGetRawAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
    }[/b]
```

**从字面上可以大致看到是相对于设备屏幕。**
详细参见图片

![](http://dl2.iteye.com/upload/attachment/0104/2053/d2f29761-254a-3b76-bbf4-5d6feb468453.png)