2013-07-24 2 views
2

DiaglogFragment 윈도우의 너비와 높이의 크기를 조정하려고하지만 아래 코드가 대화 상자 창의 크기 조정 된 버전을 제공하지 않고 대신 기본 동작보기가 수정되었습니다. 나는 또한 xml을 수정하려고 시도했지만 여전히 실패했다.DiaglogFragment 윈도우 사용자 정의

getDialog()을 사용하는 방법에 대해 잘 모르겠으나 오류가 계속 발생합니다. dialog_fragment.xml은 너비와 높이가 완전히 사용자 정의되도록 수정하고 싶은 레이아웃입니다.

public static class TestDialogFragment extends DialogFragment { 
    DialogFragment dialogFragment; 
public DialogFragment newInstace() { 
    dialogFragment = new TestDialogFragment(); 
    Log.d("Dialog Create", "sdf1"); 
    return dialogFragment; 
} 



@SuppressLint("NewApi") 
@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), 
             R.style.PopupTheme); 
    builder.setTitle("TestDialogFragment"); 
    builder.setView(getContentView()); 
    Dialog dialog = builder.create(); 
    Log.d("Dialog Create", "sdf2"); 
    return dialog; 

} 

private View getContentView() { 
    LayoutInflater inflater = getActivity().getLayoutInflater(); 

    LayoutParams params = getActivity().getWindow().getAttributes(); 

    params.height = 200; //fixed height 
    params.width = 200; //fixed width 

    getActivity().getWindow().setAttributes((android.view.WindowManager.LayoutParams) params); 

    //getDialog().getWindow().setLayout(200, 200); 

    Log.d("Dialog Create", "sdf3"); 
    return inflater.inflate(R.layout.dialog_fragment, null); 

} 
} 

이 나를 위해 트릭을 할

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
android:layout_height="match_parent" 
    android:minWidth="250dp" 
    android:minHeight="250dp" 
    > 


</RelativeLayout> 
+0

마찬가지로 getActivity(). getWindow(). getAttributes();'당신은 무엇을 바꿀 것으로 예상합니까? – Luksprog

+0

표시 할 대화 상자보기를 수정하고 싶지만 주보기가 해당 코드의 영향을받는 것이므로 getDialog를 사용하려고했지만 오류가 발생했습니다. 'inflater.inflate (R.layout.dialog_fragment, null)'-이 XML을 수정하고 싶습니다. – rahstame

답변

0

dialog_fragment.xml,

내가 할 필요가 onCreateView()

private View getContentView() { 
    View rowView = inflater.inflate(R.layout.dialog_fragment, null); 

    return rootView; 
} 
에서이 코드를 제거하는 것입니다
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
android:layout_height="match_parent" 
    android:minWidth="250dp" 
    android:minHeight="250dp" 
    > 

관련 문제