【问题标题】:Android Creating touchscreenAndroid 创建触摸屏
【发布时间】:2015-08-26 15:23:23
【问题描述】:
private String TAG = GestureActivity.class.getSimpleName();

float initialX, initialY;

@Override
public boolean onTouchEvent(MotionEvent event) {
    //mGestureDetector.onTouchEvent(event);

    int action = event.getActionMasked();

    switch (action) {

        case MotionEvent.ACTION_DOWN:
            initialX = event.getX();
            initialY = event.getY();
            AllocationAdapter imageView = null;

            imageView.setX((int) initialX);

            imageView.setY((int) initialY);

            Log.d(TAG, "Action was DOWN");
            break;
    }

    return super.onTouchEvent(event);
}

此时我收到错误消息。

【问题讨论】:

  • 您收到什么类型的错误?
  • 欢迎来到 SO!请列出您收到的错误。
  • 我的应用程序被停止错误
  • 在此站点上搜索如何查看 logcat 以及如何读取堆栈跟踪。

标签: android project touchscreen


【解决方案1】:

您的对象imageView 为空,因此您不能使用 imageView.setX() 或 imageView.setY()。

你需要用方法创建一个:

  • AllocationAdapter create1D(RenderScript rs,分配 a)
  • AllocationAdapter create2D(RenderScript rs,分配 a)
  • AllocationAdapter createTyped(RenderScript rs,分配 a,类型 t)

【讨论】:

  • 您是否可以提供网站名称的更多信息
  • 我是从here 那里得到的,但这似乎是一个高级概念。也许这不是你真正想要的。你能解释一下触摸的用途吗?
  • 触摸对象会朝那个方向移动
  • 我猜这是您要移动的 imageView。 Maybe look here for what you want.
【解决方案2】:

此行发生错误

imageView.setX((int) initialX);

因为您试图为 null 对象设置值

初始化imageView

【讨论】:

  • 代码中哪里标识了imageView.setX((int) initialX);
猜你喜欢
  • 1970-01-01
  • 2018-03-27
  • 1970-01-01
  • 1970-01-01
  • 2014-03-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-06
  • 1970-01-01
相关资源
最近更新 更多