【问题标题】:Filter for Axis Y on MotionEvent object过滤 MotionEvent 对象上的 Y 轴
【发布时间】:2013-12-05 19:26:40
【问题描述】:

有没有办法从仅提取 X 轴运动(手势)的 MotionEvent 对象创建新对象?

@Override
public boolean onTouchEvent(MotionEvent event) {
MotionEvent xMotionEvent = filterYMotion(event);
return super.onTouchEvent(xMotionEvent);
}

谢谢。

【问题讨论】:

  • 如果您想将 y 值“归零”,请使用 transform()

标签: android touch-event motionevent


【解决方案1】:

您可以使用此代码仅提取 x 值:

event.getX();

【讨论】:

  • 我需要一个 MotionEvent 对象作为结果,而不仅仅是 X 值
【解决方案2】:
@Override
    public boolean onTouchEvent(MotionEvent event) {
        Matrix matrix = new Matrix();
        matrix.setScale(1, 0);
        event.transform(matrix);
        return super.onTouchEvent(event);
    }

【讨论】:

    猜你喜欢
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-14
    • 1970-01-01
    相关资源
    最近更新 更多