Android Calendar View, show only 2 weeks

本小妞迷上赌 提交于 2019-12-13 15:27:14

问题


Is there a way to display a calendarview for 2 weeks at a time instead of the full month(4 weeks)? Please see the attached images.

I would still like to retain the gestures

  1. Scrolling left/right will change months
  2. Scrolling up/down will show me the following weeks.

Hoping that someone can point me in the right direction. Thank you!


回答1:


for this what I did was the following

  1. Create View pager (to mimic swiping left and right of a calendar)
  2. In the view pager adapter, use fragments (MonthFragment) per page that holds a Gridview. Make sure that your Gridview only shows 2 rows at a time
  3. Use an adapter to populate the Gridview elements with the dates. *there are examples online
  4. Implement a snap function for when you are scrolling the gridview vertically by setting an onTouchListener to the Gridview and snapping it up or down depending on the current movement.

This isn't perfect, but this solved my problem. Hoping that it will help others.




回答2:


I would imagine subclassing the CalendarView class to create something like "FortnightCalendarView" would be your best bet. Then you can override the display to limit it to 2 weeks. I would still use the left/right buttons to navigate fortnights instead of months, or possibly create an addition set of left-right buttons.



来源:https://stackoverflow.com/questions/38953036/android-calendar-view-show-only-2-weeks

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