2012-03-02 10 views
7

popupwindowに左右の余白を設定したい。 layoutにレイアウトパラメータを設定してから、マージンを設定しますが、動作しません。android:PopupWindowの余白をコードで設定する

は、誰もがここでコードが

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); 

おかげで

popupwindow

にマージンを設定するための私のコードを与えることができます。

答えて

9

あなたのレイアウトは、ウィンドウの一番上で、あなたはとてもあなたが使用することができますSLL側のマージン10を設定するために、幅とスクリーンの高さを使用することによって、動的にこれをやっているよう:

実際
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); 
0
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); 

、layoutParams.setMargins(left、top、right、bottom)の形式です。

+0

ratePwがサポートされていませんaddView – Jovan

+0

これを試してください: 'ratePw.update(int Left_Margin、int Top_Margin、int Width、int Height);'動作するように幅を調整します –

+0

popupwindowのレイアウトパラメータに余裕を与えることはできません。これは役に立たない。私は上記の解決策を試してみました。 –

関連する問題