【问题标题】:Only current month is visible in CalendarPickerViewCalendarPickerView 中仅显示当前月份
【发布时间】:2018-06-22 12:48:03
【问题描述】:

我正在使用 CalendarPickerView 从日历中选择多个日期。我可以制作日历,但发生的事情是,我只能看到日历的一个月(在我的情况下是当前月份)。没有更多的月份可见。我不明白这个问题。我已经尝试了多段代码,但我仍然只看到日历的一个月。如何向用户显示我提供的一年中的所有月份(1 年)?

截图:

布局:

 <com.squareup.timessquare.CalendarPickerView
      android:id="@+id/calendar_view"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:scrollbarStyle="outsideOverlay"
      android:clipToPadding="false"
      android:background="#FFFFFF"
      android:layout_alignParentTop="true"
      android:layout_above="@+id/btn_show_dates"/>

Activity的OnCreate中的代码:

final CalendarPickerView calendar_view = 
findViewById(R.id.calendar_view);
Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
Date today = new Date();
calendar_view
    .init(today, nextYear.getTime())
    .inMode(CalendarPickerView.SelectionMode.MULTIPLE)
    .withSelectedDate(today);

我也在 ScrollView 中添加了布局,我认为这是一些可见性问题,但没有任何效果。

【问题讨论】:

  • This is a fairly large control so it is wise to give it ample space in your layout. On small devices it is recommended to use a dialog, full-screen fragment, or dedicated activity. 来自其文档。
  • 我使活动上的所有其他组件的可见性都消失了,仍然没有成功!
  • 在对话框中添加日历布局有效。谢谢!

标签: android datepicker calendar


【解决方案1】:

我访问了com.squareup.timessquare.CalendarPickerViewGithub site,在页面描述中看到以下内容:

视图的默认模式是有一个可选择的日期。如果您希望用户能够选择多个日期或日期范围,请使用 inMode() 方法:

calendar.init(today, nextYear.getTime())
    .inMode(RANGE);

所以请尝试RANGE

您可以从here 看到CalendarPickerView 类。

如果您能解决您的问题,请告诉我。我没有机会尝试您的代码和可能的解决方案代码。

祝你有美好的一天!

编辑

RANGEMULTIPLE 似乎都有效。但是,请删除&lt;ScrollView&gt; 并重试。我现在试过了,它奏效了! :)

【讨论】:

  • Multiple 是一个有效值。它在 SelectionMode 的选项中可用。
  • 是的,是的,你是对的。一开始我错了,但我现在试着更好地解释它。对困惑感到抱歉。但是,我再次根据他们的解释更新了我的解决方案。
  • @Yesha 我试过了,它对我有用。请查看已编辑的部分。 :)
猜你喜欢
  • 2019-08-17
  • 1970-01-01
  • 2013-05-05
  • 2018-04-06
  • 1970-01-01
  • 1970-01-01
  • 2018-10-08
  • 1970-01-01
  • 2021-12-06
相关资源
最近更新 更多