I want to set the left and right fields in popupwindow. I am trying to set the layout options to layout and then set the margin but not work.
layout
Can someone give me code to set the field in popupwindow
Here is the code
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(WindowManager.LayoutParams.FILL_PARENT); ratePw.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); ratePw.setFocusable(true); ratePw.showAtLocation(layout, Gravity.CENTER, 0, 0);
Thanks.
since your layout is at the top of the window and you do it dynamically using the width and height of the screen, so to set field 10 on the 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);
LayoutParams parm1=new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); parm1.setMargins(20, 20, 0, 0); layout.setLayoutParams(parm1); //ratePw.addView(layout,parm1); // removed it ratePw.setContentView(layout);
Actually, the layoutParams.setMargins format (left, top, right, bottom);