Roger
Roger

Reputation: 6527

How to get LinearLayout's X and Y coordinates?

Say I have created a linearlayout ( linLayBtn ) and added it to an already existing in the xml linearlayout ( linLayRow )...

linLayRow.addView(linLayBtn, linLayBtnPar);

And now I need to know the X and Y coordinates of the linLayBtn layout that I just added.

How would you do that?

Upvotes: 0

Views: 1880

Answers (3)

Mustafa Güven
Mustafa Güven

Reputation: 15744

currentsdk < sdk 11

getLeft(), getTop()

currentsdk >= sdk 11

getX(), getY()

Upvotes: 0

MrJre
MrJre

Reputation: 7161

x = linLayBtn.getX();
y = linLayBtn.getY();

Just remember that calling this in the constructor gives back 0 because views have to be measured and laid out first.

Upvotes: 1

Rasel
Rasel

Reputation: 15477

x=linLayBtn.getLeft();
y=linLayBtn.getTop();

Upvotes: 1

Related Questions