Joyson
Joyson

Reputation: 1653

Programmatically determine the coordinates of a view(Button) in android?

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?

Upvotes: 0

Views: 1708

Answers (3)

Chirag
Chirag

Reputation: 56925

Here is the solution . Please check the link for find out the screen location of the View.

Upvotes: 1

Oibaf it
Oibaf it

Reputation: 1952

Try to see the methods getLocationInWindow and getLocationOnScreen.

http://developer.android.com/reference/android/view/View.html#getLocationInWindow(int[])

Upvotes: 0

knvarma
knvarma

Reputation: 974

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.

Upvotes: 0

Related Questions