我如何获得用户在 android 视图上单击的点/坐标? [英] How do i get the point/coordinate the user clicked on an android view?

查看:13
本文介绍了我如何获得用户在 android 视图上单击的点/坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 imageview,点击后会调用 OnClickListener.onClick(View v).如何获取用户点击的确切点/坐标?

I have an imageview and when clicked, calls OnClickListener.onClick(View v). How do I get the exact point/coordinate that the user clicked?

谢谢

推荐答案

在 OnClickListerner 中无法获取触摸到的坐标.请使用 OnTouchListener.onTouch(View v, MotionEvent event) 代替它,并且您可以从事件中获取坐标.

You can't get the coordinate touched in OnClickListerner. Please use OnTouchListener.onTouch(View v, MotionEvent event) instead of it, and you could get the coordinate from the event.

这篇关于我如何获得用户在 android 视图上单击的点/坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆