Как изменить размер DialogFragment
У меня есть диалоговое окно в моем приложении Android с некоторыми видами, как вы можете видеть на изображении ниже:
Я пытаюсь изменить его размер без успеха, в Java-классе я пытаюсь сделать это: getDialog().getWindow().setLayout(800,800);
getDialog().setTitle("Please tell us");
как вы можете видеть в коде ниже:
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.d(TAG, "onCreateView(LayoutInflaterm ViewGroup, Bundle) - Ini ");
View view = inflater.inflate(R.layout.dialog_box_layout, container, false);
ageSpinner = (Spinner) view.findViewById(R.id.age_spinner_dialog);
ageSpinner.setSelected(false);
ageSpinner.setAdapter(populateAgeSpinner());
ageSpinner.setOnItemSelectedListener(this);
radioDialogMale = (RadioButton) view.findViewById(R.id.radioDialogM);
radioDialogMale.setSelected(false);
radioDialogMale.setOnClickListener(this);
radioDialogFemale = (RadioButton) view.findViewById(R.id.radioDialogF);
radioDialogFemale.setSelected(false);
radioDialogFemale.setOnClickListener(this);
okButton = (Button) view.findViewById(R.id.dialog_ok);
okButton.setOnClickListener(this);
getDialog().getWindow().setLayout(800,800);
getDialog().setTitle("Please tell us");
communicator = (LoginActivity) getActivity();
setCancelable(false);
Log.d(TAG, "onCreateView(LayoutInflaterm ViewGroup, Bundle) - Fi ");
return view;
}
но ничего не меняется.
вот файл макета:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000">
<!-- <TextView
android:id="@+id/dialog_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please tell us your age and gender"
android:textSize="22dp"
android:layout_marginTop="15dp"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textColor="#FFF"
android:textStyle="bold"
android:layout_marginBottom="30dp"/> -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:text="Age"
android:textSize="18dp"
android:gravity="center"/>
<Spinner
android:id="@+id/age_spinner_dialog"
android:layout_width="80dp"
android:spinnerMode="dropdown"
android:layout_height="30dp"
android:layout_marginLeft="18pt"
android:foregroundTint="@color/com_facebook_button_send_background_color"
android:backgroundTint="#FFF"/>
<TextView
android:id="@+id/text_gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50pt"
android:text="Gender"
android:textColor="#FFF"
android:textSize="18dp"
android:layout_alignTop="@+id/radioGroup"
android:layout_toEndOf="@+id/age_spinner" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="0.70"
android:layout_marginEnd="25dp"
android:layout_marginLeft="20dp"
android:id="@+id/radioGroup"
android:layout_alignParentEnd="true">
<RadioButton
android:layout_width="50dp"
android:layout_height="25dp"
android:text="M"
android:layout_marginLeft="12dp"
android:id="@+id/radioDialogM"
android:layout_marginBottom="30dp"
android:textColor="@color/com_facebook_button_send_background_color"
android:backgroundTint="@color/com_facebook_button_send_background_color"
android:buttonTint="@color/com_facebook_button_send_background_color"/>
<RadioButton
android:layout_width="50dp"
android:layout_height="25dp"
android:text="F"
android:id="@+id/radioDialogF"
android:layout_marginRight="5pt"
android:textColor="@color/com_facebook_button_send_background_color"
android:backgroundTint="@color/com_facebook_button_send_background_color"
android:buttonTint="@color/com_facebook_button_send_background_color"/>
</RadioGroup>
/>
<Button
android:layout_width="wrap_content"
android:layout_height="30dp"
android:id="@+id/dialog_ok"
android:background="@color/com_facebook_button_send_background_color"
android:textColor="#FFF"
android:text="OK"
android:layout_below="@+id/radioGroup"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp" />
</RelativeLayout>
Помогите, пожалуйста!!!
1 ответ
Решение
Вы можете попытаться установить ширину и высоту фрагмента диалога из метода onResume(). как ниже:
public void onResume()
{
super.onResume();
Window window = getDialog().getWindow();
window.setLayout(width, height);
window.setGravity(Gravity.CENTER);
//TODO:
}
Я нашел это решение здесь: Установка размера DialogFragment