Refine Tshingila
Refine Tshingila

Reputation: 45

Getting the coordinates of a button

How do you get the coordinates (x,y) of the corners of a button.

I've tried getting the y value of the right top corner by: (yCordOfButton) - (heighOfButton/2)...with that, it almost works but doesn't quite work the precise way I need it to

Upvotes: 0

Views: 42

Answers (1)

Nathan Brooks
Nathan Brooks

Reputation: 26

You can get the top left corner of the screen by using View.getLocationOnScreen(int[]) and then you can use the height and width to get the other corners as needed. getLocationOnScreen is documented here.

Upvotes: 1

Related Questions