Android set margin of view programmatically
Manually set width and height of PopupWindow :
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
popupWindow.setWidth(width-10);
popupWindow.setHeight(height-10);
try to use layout it will work
LinearLayout.LayoutParams params = new LayoutParams
(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
);
params.setMargins(left, top, right, bottom);
yourbutton.setLayoutParams(params);
follow this tutorial http://www.codota.com/android/classes/android.view.ViewGroup.MarginLayoutParams