JithinMechery
JithinMechery

Reputation: 53

Get parameters of relative layout in android

In android , i am creating a button in relative layout.i want to know the x and y possition of button

button_open=(Button)findViewById(R.id.btn_alert); button_x=button_open.getX(); button_y=button_open.getY();

but i get 0.0, 0.0 respectivelyt for the floating variables button_x,button_y.

Upvotes: 0

Views: 107

Answers (2)

duggu
duggu

Reputation: 38439

try below way to achieve your goal:-

view.getLocationInWindow()

or

view.getLocationOnScreen()

for more info see below link:-

Retrieve the X & Y coordinates of a button in android?

Upvotes: 1

Blackbelt
Blackbelt

Reputation: 157487

you should give the system the time to measure/layout the object. View can either register a ViewTreeObserver, or post a runnable on the root layout and retrieve those information when the runnable is executed

Upvotes: 0

Related Questions