我已经编写了一些代码来从ImageView获取位置。以下是我的代码:
private void touchLocation(MotionEvent e){
float x = e.getX();
float y = e.getY();
String message = "Location is x = " + x + ", y = " + y ".";
Context context = getApplicationContext();
int duration = Toast.LENGTH_LONG:
Toast toast = Toast.makeText(context, message, duration);
toast.show();
}
在onCreate()方法中,我该如何调用此函数?任何建议都非常感谢。如何使用MotionEvent类实例化对象?
答案 0 :(得分:1)
imageView.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent e) {
float x = e.getX();
float y = e.getY();
String message = "Location is x = " + x + ", y = " + y ".";
// more code
return true;
}
});