我想在一个Dialog中使用DatePicker和TimePicker。在大屏手机中,效果很好,但在小屏手机中,它似乎太大了。而且我使用的是API8,我无法使用setScaleX()/setScaleY( )。
我怎么做 ?或者还有其他方法可以在一个对话框中显示 datepicker 和 timepicker 吗?谢谢。
这是 datetimepicker_layout.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<DatePicker
android:id="@+id/datepicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TimePicker
android:id="@+id/timepicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TimePicker>
</LinearLayout>
在java文件中:
private void showDateTimeDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
View v = getLayoutInflater().inflate(R.layout.datetimepicker_layout,
null);
TimePicker tp = (TimePicker) v.findViewById(R.id.timepicker);
tp.setIs24HourView(true);
//hidden the minute picker
View minuteView = ((View) ((LinearLayout) tp.getChildAt(0))
.getChildAt(1));
minuteView.setVisibility(View.GONE);
OnClickListener listener = new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Log.d(tag, "onClick " + "which " + which);
}
};
builder.setView(v).setTitle("order time").setPositiveButton("ok", listener)
.setNegativeButton("cancel", listener).create().show();
}
ps: