我有一个DatePickerFragment,它使用一个非常简单的自定义布局。在较小的设备上(HTC One m7),该布局占用整个警告对话框,但在Nexus 6上不占用整个宽度。有人知道为什么DatePicker没有占满Nexus 6警告对话框的整个宽度或从哪里开始进行故障排除吗?谢谢!
Nexus 6(请注意,日期标题未填充整个警告对话框)
DatePickerFragment的onCreateDialog()函数
Nexus 6(请注意,日期标题未填充整个警告对话框)
HTC One m7
dialog_date.xml
<?xml version="1.0" encoding="utf-8"?>
<DatePicker xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialog_date_date_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:calendarViewShown="false">
</DatePicker>
DatePickerFragment的onCreateDialog()函数
public Dialog onCreateDialog(Bundle savedInstanceState) {
Date date = (Date) getArguments().getSerializable(ARG_DATE);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
View v = LayoutInflater.from(getActivity())
.inflate(R.layout.dialog_date, null);
mDatePicker = (DatePicker)
v.findViewById(R.id.dialog_date_date_picker);
mDatePicker.init(year, month, day, null);
return new AlertDialog.Builder(getActivity())
.setView(v)
// .setTitle(R.string.date_picker_title)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int year = mDatePicker.getYear();
int month = mDatePicker.getMonth();
int day = mDatePicker.getDayOfMonth();
Date date = new GregorianCalendar(year, month, day).getTime();
sendResult(Activity.RESULT_OK, date);
}
})
.create();
}