Reputation: 20223
I have an ImageButton and I would like to set its position programmatically to x and y.
How can I do this? I read something abaut setTop() and setLeft() but don't know how to use it.
Upvotes: 0
Views: 1482
Reputation: 13752
AbsoluteLayout.LayoutParams params = new AbsoluteLayout.LayoutParams(
int width, int height, int x, int y);
params.x=30;
params.y=50;
imageButton.setLayoutParams(params);
using this code you can position you item in absolute (x,y) coordinate in your view, but you need to use you main root layout AbsoluteLayout otherwise it throws error.
But AbsoluteLayout is depreciated in latest version so avoid that , try to use RelativeLayout
Upvotes: 2