安卓3.0 CalendarViewCalendarView

2023-09-06 13:34:48 作者:共赴春秋

我想实现一个 CalendarView 的,它需要时间的荒谬量(约10秒),以显示在屏幕上,而且只加载月和星期标头,它不显示任何日程内容

I'm trying to implement a CalendarView, it takes an absurd amount of time (about 10 seconds) to appear on screen and it only loads the month and weekday headers, it does not display any calendar content.

使用此影片相同的code,但没有看到同样的结果。我试图启动它在一个对话框:

Using the same code from this video but not seeing the same result. I'm trying to launch it in a dialog:

CalendarView calendarView =新CalendarView(本); dialog.setContentView(calendarView);

CalendarView calendarView = new CalendarView(this); dialog.setContentView(calendarView);

但是当我试图将它嵌入在它采取了屏幕的时间是相同的加载和类似的活动未能正确显示。

but when I tried to embed it in an activity it took the screen the same amount of time to load and similarly failed to display correctly.

推荐答案

的跟踪帮助揭示的GregorianCalendar正在调用数千次。 看来,当日历天是不可见的,它会尝试计算所有的日期,而不仅仅是可见的。

The tracing helped reveal that GregorianCalendar was being called thousands of times. It seems that when the calendar days aren't visible, it tries to calculate all of the dates rather than just the visible ones.

的CalendarView只显示标题信息这个问题是由 layout_width layout_height 明确设置解决。无论是 WRAP_CONTENT match_parent 工作正常显示日历的内容。

The issue of the CalendarView only displaying the header information was solved by setting the layout_width and layout_height explicitly. Neither wrap_content or match_parent worked properly to display the calendar contents.