I am writing a method that draws a layout ontop of buttons. My problem is with the position of the layout that I am creating on lower API's. On newer I am using the setX()
and setY()
methods but since that is not working on lower I tried with setting the layout params as described here Android - Use of view.setX() and setY in api 8 but I am not getting the results I want. With this
int[] location = new int[2];
button.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
borderRelativeLayout.setX(x);
borderRelativeLayout.setY(y);
viewGroup.addView(borderRelativeLayout)
I am achieving this: correct position
but if I use this code to support lower API's
relativeLayoutparams.leftMargin = x;
relativeLayoutparams.topMargin = y;
viewGroup.addView(borderRelativeLayout, relativeLayoutparams);
I am getting this as a result: incorrect
Any help would be appreciated.