Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing position of a button

I have one button in an AbsoluteLayout in an XML file. From there I am able to set the (x,y) position of the button.

How can I get and set the (x,y) coordinates of the button programmatically?

Thanks all.

like image 511
Vishal Arora Avatar asked Apr 13 '11 09:04

Vishal Arora


1 Answers

You have to get a reference to you button, for example by calling findViewById(). When you got the reference to the button you can set the x and y value with button.setX() and button.setY().

....
Button myButton = (Button) findViewById(R.id.<id of the button in the layout xml file>);
myButton.setX(<x value>);
myButton.setY(<y value>);
....
like image 147
Flo Avatar answered Oct 05 '22 06:10

Flo