我有一个奇怪的问题。我有一个继承了AppCompatActivity
的Activity
,里面包含一个 Fragment
。
在这个Fragment
中,我展示了一个 DatePickerDialog
来选择日期。
在manifest.xml
中声明了一个Activity
:
<activity name=".SampleActivity" android:configChanges="keyboardHidden|orientation|screenLayout|screenSize" />
现在,我想在Fragment
中显示DatePickerDialog
,所以我创建了自定义的DatePickertFragment
:
public class DatePickerFragment extends AppCompatDialogFragment{
// (...)
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, year, month, day);
return dialog;
}
// (...)
}
并在片段内执行show()方法
pickerFragment.show(getChildFragmentManager(), null);
我在onClick()
方法中运行显示选择器的代码,DatePicker
正确显示。
但是现在有一个问题。在纵向屏幕方向下,Dialog
正确显示,但是当我旋转屏幕到横向模式时,对话框似乎被剪切在左侧和右侧。我检查过,认为Dialog
选择器没有在屏幕旋转时更改布局方向。以下是截图。
1. 纵向方向,正确的对话框
I changed manifest.xml
Activity
declaration to
android:configChanges="keyboardHidden|orientation"
And now is work correctly but I can't do this, because other app part will work incorrect.
So I wonder if I can invalidate or redraw DialogPicker
to resize it boundaries after I rotate screen?