how to get x and y coordinates of user tap/touch r

2019-08-19 07:10发布

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?

3条回答
Melony?
2楼-- · 2019-08-19 07:29

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.

查看更多
\"骚年 ilove
3楼-- · 2019-08-19 07:35

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

Titanium.UI.Window

查看更多
啃猪蹄的小仙女
4楼-- · 2019-08-19 07:36

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

查看更多
登录 后发表回答