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:

  1. extend view , override ondraw example or other method need
  2. like said, call onclick, since time ui layout , rendered properly

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -