在屏幕上点的Android记录坐标 [英] Android recording coordinates of the point in screen
问题描述
我的活动应当记录在屏幕上的一个点,该用户可以移动的坐标。具体地说,用户触摸屏幕和关于该项目,这将成为能够移动出现。当你抬起手指,点的坐标,应recorded.Please的建议。
My activity should record the coordinates of a point on the screen, which the user can move. Specifically, the user touches the screen and appears on the item, which will be able to move. When you lift your finger, the coordinates of the point should be recorded.Please for your advice.
推荐答案
EDITED 这里是一个祝酒用户触摸和触摸起来统筹整个简单的活动
EDITED Here is whole simple activity which Toasts the user touch down and touch up co-ordinates
import android.os.Bundle;
进口android.app.Activity;
import android.app.Activity;
进口android.view.MotionEvent;
import android.view.MotionEvent;
进口android.widget.Toast;
import android.widget.Toast;
公共类MainActivity延伸活动{
public class MainActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Toast.makeText(getApplicationContext(), "Touch Down x="+x+" y="+y ,Toast.LENGTH_SHORT).show();
//Handle Touch Down
break;
case MotionEvent.ACTION_MOVE:
//Handle Touch Move
break;
case MotionEvent.ACTION_UP:
Toast.makeText(getApplicationContext(), "Touch Up x="+x+" y="+y ,Toast.LENGTH_SHORT).show();
//Handle Touch Up
break;
}
return false;
}
}
这篇关于在屏幕上点的Android记录坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!