![Android开发之触摸事件-点击屏幕获得屏幕的坐标 Android开发之触摸事件-点击屏幕获得屏幕的坐标](https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif)
.xml文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
</LinearLayout>
.java文件
package com.example.touchproject;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView info=null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.info=(TextView) super.findViewById(R.id.info);
//添加触摸事件
this.info.setOnTouchListener(new TouchListenerImp());
}
private class TouchListenerImp implements OnTouchListener{
public boolean onTouch(View v, MotionEvent event) {
MainActivity.this.info.setText("x="+event.getX()+"y="+event.getY());
return false;
}
}
}