I\'m coding with API 8.
I need to get coordinates X and Y from a View and and set them as the coordinates of a new Button.
I tried different ways but nothing works....<
I haven't tried this, but I think it will work:
int buttonX = 50; // Arbitrary values - use whatever you want
int buttonY = 100;
int viewX = myView.getLeft();
int viewY = myView.getTop();
Button newButton = new Button();
newButton.setPadding(buttonX - viewX, buttonY - viewY, 0, 0);
// Other button setup
That will set it to an absolute position of (50,100) on the screen. If you want it to be (50,100) relative to the corner of your layout then use this:
int buttonX = 50; // Arbitrary values - use whatever you want
int buttonY = 100;
Button newButton = new Button();
newButton.setPadding(buttonX, buttonY, 0, 0);
// Other button setup
This will only work on layouts that don't automatically position their child content, such as RelativeLayout.