How to determine the coordinates (position ) of a view in android programmatically? I have a button placed in my xml file .How do i determine the coordinates of that button in java code?
Asked
Active
Viewed 1,670 times
3 Answers
1
Here is the solution . Please check the link for find out the screen location of the View.

Chirag
- 56,621
- 29
- 151
- 198
0
get the view reference in java code.
Integer [] location = new Integer[];
view.getLocationOnScreen(location);
Now the integer array contains the co-ordinates of your view on screen.

knvarma
- 974
- 5
- 6
-
1Its always showing 0 value in both of the items of array. Can you help me with that. – Salman Khan Jul 08 '14 at 10:30
0
Try to see the methods getLocationInWindow and getLocationOnScreen.
http://developer.android.com/reference/android/view/View.html#getLocationInWindow(int[])

Oibaf it
- 1,842
- 16
- 9