Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (absolute)
Viewing all articles
Browse latest Browse all 6

Finding absolute screen coordinates of a View

$
0
0

Hi,

I have a view on a tablerow that is clickable. When I click it I like to start an animation from that view growing into a popup. For this I need to know exactly the top,left coodinates of the view as well as the size. The latter is fine, while I have a hard time with the top,left coordinates.

My attempt was to traverse the view hierarchy upwards while adding the left and top coords. I would have thought that would equal the screen coords ... unfortunately it does not.

function findAbsoluteScreenLocation(component) {
    var x = component.rect.x;
    var y = component.rect.y;
    while (component.getParent() != null) {
        var parent = component.getParent();
        x += parent.rect.x;
        y += parent.rect.y;
        component = parent;
    }
    return { x: x, y: y }
}

Anyone with some smart trick here? Is it possible to get this information directly w/o traversing the UI-hierarchy?


Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>