android: set margin on PopupWindow by code

as your layout is top on window, and you are doing this dynamically, by using width and height of screen, so to set margin 10 on sll side you can use:

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;

LayoutInflater inflater = (LayoutInflater) QuestionsActiviy.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.popup, (ViewGroup) findViewById(R.id.popup_element));


ratePw = new PopupWindow(layout);
ratePw.setWidth(width-20);
ratePw.setHeight(height-20);
ratePw.setFocusable(true);

Tags:

Android