Android CalendarView Drops Weeks at Random

为君一笑 提交于 2019-12-13 02:31:31

问题


I'm using the standard CalendarView in one of my projects. When I display it in a dialog, it seems to work normally, but when I display it in another activity in the app, it seems to leave out a few weeks at random. Scrolling up and down through the calendar causes them to appear again, but others to disappear. Often the missing week is the one including the date that I set it to using setDate() so no selected date is even shown.

Has anyone else seen this behavior with CalendarView? I'm using SDK v17.

    <CalendarView
        android:id="@+id/cv_planner"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:padding="@dimen/item_list_padding"
        android:selectedDateVerticalBar="@color/teal"
        android:selectedWeekBackgroundColor="@color/teal"
        android:showWeekNumber="true" />

回答1:


As a temporary fix, force a refresh by scrolling down/up a month or two, and then scroll back. You should see that the refresh causes the missing week to appear.

Provided this is truly a bug with no workaround, the code involved to compensate for this wouldn't be trivial. I'd imagine it would involve posting a runnable method on your UI thread from the containing activity that would analyze the view after its rendered to check for a missing week, and then forcing a refresh of the view somehow (This would be "easiest" way before getting into sub-classing the CalendarView itself and trying to control its rendering at a finer granularity, say through onMeasure or onLayout).

Update: Found a workaround - CalendarView Issues when Used Directly (Outside of a DatePicker)



来源:https://stackoverflow.com/questions/17518677/android-calendarview-drops-weeks-at-random

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!