[ACCEPTED]-Changing position of a button-absolutelayout
You have to get a reference to you button, for 3 example by calling findViewById(). When you got the reference 2 to the button you can set the x and y value 1 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>);
....
The answer you're looking for is in LayoutParams
. Firstly, I'd 5 suggest not using AbsoluteLayout -- it's deprecated 4 -- and using something else, maybe a FrameLayout, and 3 just using the left and top margins as your 2 x and y offsets.
However, to answer your 1 question:
Button button = (Button)findViewById(R.id.my_button);
AbsoluteLayout.LayoutParams absParams =
(AbsoluteLayout.LayoutParams)button.getLayoutParams();
absParams.x = myNewX;
absParams.y = myNewY;
button.setLayoutParams(absParams);
Or alternatively:
Button button = (Button)findViewById(R.id.my_button);
button.setLayoutParams(new AbsoluteLayout.LayoutParams(
AbsoluteLayout.LayoutParams.FILL_PARENT, AbsoluteLayout.LayoutParams,
myNewX, myNewY));
hummm u can try this. . . Is there an easy way to add a border to the top and bottom of an Android View? Just go threw 3 this site u will get the Sollution. If not 2 then reply to me. And if its help u then 1 give me a vote. Thanks.
Try using the layout-method of the View: http://developer.android.com/reference/android/view/View.html#layout(int,%20int,%20int,%20int)
0
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.