Reputation: 11
I have one button in an linear Layout . 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 by java program ?
Upvotes: 1
Views: 5073
Reputation: 2266
u cant do this with linear layout use Relative layout for positioning the component to absolute position inside parent view.
https://stackoverflow.com/a/3295056/1405008
refer the above answer for more information.
Upvotes: 1
Reputation: 12042
LinearLayout.LayoutParams btn = new LinearLayout.LayoutParams(
R.id.layout_name);
btn.leftMargin = myXPosition;
btn.topMargin = myYPosition;
btn.width = buttonW;
btn.height = buttonH;
myButton.setLayoutParams(btn);
Upvotes: 0