问题
I want that when i click on my MainView, i want to create new window just where i have touched.
Say for e.g. i have clicked at top:50 left:200
then my new window should start from that point only.
I want to create something like Popover in Titanium
for android
. Can anyone just guide me?
Thanks in advance.
回答1:
consider you have a window win thats going to fire the click event like that:
win.addEventListener('click',function(e){
var myPopUp = createPopUp({
left: e.x,
top: e.y
});
myPopUp.open();
});
your popup could be created like that:
createPopUp = function(_args){
var popup = Titanium.UI.createWindow({
backgroundColor: 'red', /* a backgroundImage could be better */
height: '250dp',
width: '250dp',
top: _args.top, /* manually adjusted */
left: _args.left,
opacity: 0.7 /* for a nice transparency*/
});
return popup;
};
this works at android and iphone. the top values seems to be a little unprecise but in general it works.
回答2:
In regards to getting the touch coordinates for the parent view you should attach the event listener to the parent view (or both if you can't get the source and need different actions) because if I'm correct the touch event (or any other for event that matter) should propagate to parent/child views too. Then you can simply get the e.source.top
and e.source.left
values as you need.
回答3:
You can place this way PopupWindow, using its showAtLocation method.
This allows to place the window in desired position, relative to your main view. And you know where user clicked on your main view.
来源:https://stackoverflow.com/questions/9437383/how-to-get-the-touch-point-top-and-left-irrespective-of-the-views-windows-in