how to get x and y coordinates of user tap/touch relative to window - android titanium mobile?

可紊 提交于 2019-12-11 23:54:49

问题


Can any one tell how to get x and y coordinates of user tap/touch relative to window - android titanium mobile??

I need to add a popup view close to tableviewrow when the user select a row. How to determine the x,y (top/left) positions?


回答1:


you can use

row.addEventListener('click',function(e){
    alert('left:'+ e.x + ' top:'+ e.y);
});

where row is an object of Titanium.UI.TableViewRow. For other objects (like window/view), you can use same eventlistener.

But remember one thing: it gives the co-ordinates with respect to the corresponding row. i.e. you may get same co-ordinates for all the rows.

Therefor, if you want to popup something on that co-ordinate, you should addEventListener to the main window.




回答2:


This might help you as the window or object touch events can help you find the exact points the user have touched on screen. thanks




回答3:


On click event of any view or object you get x and y coordinate see this link for more reference:

Titanium.UI.Window



来源:https://stackoverflow.com/questions/11671451/how-to-get-x-and-y-coordinates-of-user-tap-touch-relative-to-window-android-ti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!