2013-11-26 99 views
0

我有一個android.support.v4.app.DialogFragment,它顯示時,高度是最大,但是widht只是包裝內容,我需要設置自定義高度,android android.support.v4.app.DialogFragment設置大小

我已經嘗試過這樣的:

@Override 
public void onViewCreated(View view, Bundle savedInstanceState) { 
getDialog().getWindow().setLayout(2000, 2000); 
super.onViewCreated(view, savedInstanceState); 
} 

但結果總是相同的

EDIT1

這裏是XML佈局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#ffffff" 
    android:minHeight="10000dp" 
    android:minWidth="10000dp" > 

.......content 
</RelativeLayout> 

EDIT2

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     view = inflater.inflate(R.layout.marche_charts, container, false); 

     WindowManager.LayoutParams wmlp = getDialog().getWindow().getAttributes(); 
     wmlp.gravity = Gravity.CENTER; 
     wmlp.height = 2000; 
     wmlp.width = 2000; 
     getDialog().getWindow().setAttributes(wmlp); 
     return view; 
    } 
+0

類似的問題和答案[here](http://stackoverflow.com/questions/12478520/how-to-set-dialogfragments-width-and-height)或[here](http:// stackoverflow。 com/questions/14946887/setting-the-size-of-a-dialogfragment) – gunar

回答

0

在寬度和高度的XML佈局內放match_parent。

+0

我編輯了我的問題 –

0

當您爲DialogFragment創建視圖(onCreateView方法)時,請使用setMinWidth。例如

final DisplayMetrics displaymetrics = new DisplayMetrics(); 
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); 

view.setMinimumWidth((int) (Math.min(displaymetrics.widthPixels, 
     displaymetrics.heightPixels) * 0.9f)); 
+0

仍然沒有運氣... –

1

你需要重寫onActivityCreated()方法,並把這個getDialog()getWindow()的setLayout(2000,2000)。;在那裏