android view的触摸事件坐标不是屏幕坐标,是相对于view左上角的坐标。

public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        TextView tv = (TextView) findViewById(R.id.tv);        tv.setOnTouchListener(new OnTouchListener() {public boolean onTouch(View v, MotionEvent event) {System.out.println("坐标:[x,y] = [" + event.getX() + "," + event.getY() + "]");return false;}});    }


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent" >    <TextView        android:id="@+id/tv"        android:layout_width="150dp"        android:layout_height="150dp"        android:layout_centerHorizontal="true"        android:layout_centerVertical="true"        android:background="#ff00ffff"        android:gravity="center"        android:text="click me"        tools:context=".MainActivity" /></RelativeLayout>


04-10 23:27:10.889: I/System.out(10515): 坐标:[x,y] = [0.0,21.0]04-10 23:27:11.159: I/System.out(10515): 坐标:[x,y] = [3.0,21.0]04-10 23:27:11.369: I/System.out(10515): 坐标:[x,y] = [3.0,21.0]04-10 23:27:11.549: I/System.out(10515): 坐标:[x,y] = [9.0,18.0]04-10 23:27:11.699: I/System.out(10515): 坐标:[x,y] = [10.0,20.0]04-10 23:27:11.869: I/System.out(10515): 坐标:[x,y] = [13.0,20.0]

更多相关文章

  1. Android 坐标系统
  2. 学个明白--Android世界的坐标系
  3. android获取gps坐标
  4. Android View系列 - 坐标系
  5. Android AbsListView坐标体系解析
  6. android度量相对于地球坐标系的加速度
  7. Android 坐标系及动画移动坐标相关集合
  8. Android 自定义View之坐标系(一)
  9. android坐标系相关知识点

随机推荐

  1. 急求用jersey2.x+spring3.x 开发rest web
  2. 从AWS Lambda发布到SNS时超时
  3. Finder3.0 - 集群支持即将发布
  4. Java中的TreeMap、Comparable、Comparato
  5. 如何获得嵌入式Jetty Web服务器来转储其J
  6. java网上在线支付实战视频
  7. 在本地运行数据流导致JVM崩溃(OOM)
  8. 如何判断用户的java代码是否已成功编译?
  9. Byte Buddy - java.lang.NoSuchMethodE
  10. Eclipse打开出错:Java wa started but ret