Changing Position Of A Button
Solution 1:
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.<idofthebuttoninthelayoutxmlfile>);
myButton.setX(<xvalue>);
myButton.setY(<yvalue>);
....
Solution 2:
The answer you're looking for is in LayoutParams
. Firstly, I'd suggest not using AbsoluteLayout -- it's deprecated -- and using something else, maybe a FrameLayout, and just using the left and top margins as your x and y offsets.
However, to answer your question:
Buttonbutton= (Button)findViewById(R.id.my_button);
AbsoluteLayout.LayoutParamsabsParams=
(AbsoluteLayout.LayoutParams)button.getLayoutParams();
absParams.x = myNewX;
absParams.y = myNewY;
button.setLayoutParams(absParams);
Or alternatively:
Buttonbutton= (Button)findViewById(R.id.my_button);
button.setLayoutParams(newAbsoluteLayout.LayoutParams(
AbsoluteLayout.LayoutParams.FILL_PARENT, AbsoluteLayout.LayoutParams,
myNewX, myNewY));
Solution 3:
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 this site u will get the Sollution. If not then reply to me. And if its help u then give me a vote. Thanks.
Solution 4:
Try using the layout-method of the View: http://developer.android.com/reference/android/view/View.html#layout(int,%20int,%20int,%20int)
Post a Comment for "Changing Position Of A Button"