The answer you are looking for is in LayoutParams
. Firstly, I would suggest not using AbsoluteLayout - it is deprecated - and using something else, perhaps FrameLayout, and just using the left and top margins as your x and y offsets.
However, to answer your 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));
source share