我试图让时间选择器在横屏显示整个时钟。该TimePicker
位于GridLayout
中,它不像DialogFragment
或TimePickerDialog
那样覆盖屏幕。
目前,在横屏模式下会显示如下内容:
可以看到,你无法使用任何东西来选择时间,只有默认时间。我想像纵向模式(正常工作)一样显示整个时钟:
时间选择器的布局:
<package.name.ScrollableTimePicker
android:id="@+id/time_picker"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
扩展
TimePicker
的类:public class ScrollableTimePicker extends TimePicker {
public ScrollableTimePicker(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public ScrollableTimePicker(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScrollableTimePicker(Context context) {
super(context);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// Keeps events to time picker
if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
ViewParent p = getParent();
if (p != null) {
p.requestDisallowInterceptTouchEvent(true);
}
}
return false;
}
}
我在互联网上搜索并发现以下帖子没有帮助我: 我的时间选择器没有标题。 已经实施了。 尝试在清单中使用代码,但仍然不起作用。 更新 正如siddesh建议的那样,将TimePicker的
layout_height
设置为200dp
可以解决问题,但它会削减纵向。现在,Portrait是200dp
高,但被削减了一半,而Landscape则完全显示:
![高度为200dp的横向TimePicker完全显示](https://istack.dev59.com/8rqN2.webp)
![高度为200dp的纵向TimePicker,一半被削减。](https://istack.dev59.com/gp61x.webp)