Can I get the touch coordinates without using listener?
Is there any way to get the coordinates of touch (when user touch/multi-touch on activity) without using t开发者_如何学Gohe OnTouchListener event ? If it is possible, then kindly provide me any example.
Try this code:
int x, y;
TextView tv, tl;
FrameLayout fl;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.textView);
tv.setText("X Coordinate");
tl = (TextView) findViewById(R.id.touchView);
tl.setText("Y Coordinate");
}
@Override
public boolean onTouchEvent(MotionEvent e) {
x = (int) e.getX();
y = (int) e.getY();
tv.setText("" + x);
tl.setText("" + y);
return true;
}
精彩评论