java - How to find location of view once its drawn -
i've got view trying location after drawn.
below code i'm using that.
view.getviewtreeobserver().addongloballayoutlistener(new ongloballayoutlistener{ @override public void ongloballayout(){ int[] location = new int[2]; view.getlocationonscreen(location); log.d("some tag","location ("+location[0]+","+location[1]+)"); });
the above code gives me 0,75. great, except if place onclicklistener there location of click (on top left corner) 0,275.
whats interesting if same process in onclicklistener, 0,275 top left corner. clues on doing wrong, or if there better place put code fetch location. has after view drawn (for obvious reasons).
thanks!
there several ways approach problem. not sure end goal here, here they:
- extend view , override ondraw example or other method need
- like said, call onclick, since time ui layout , rendered properly
Comments
Post a Comment