有没有办法在不使用 OnTouchListener 事件的情况下获取触摸坐标(当用户触摸/多点触摸 Activity 时)?如果可能,请提供任何示例。
最佳答案
试试这段代码:
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;
}
关于android - 我可以在不使用监听器的情况下获取触摸坐标吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6591805/