Android. CalendarView…show only one month calendar at a time

孤街浪徒 提交于 2020-01-14 10:45:13

问题


i am using CalendarView in which i want to view only one month calendar at a time and view next month on scroll but CalendarView shows all the month at a time. below is my code.

<CalendarView
    android:id="@+id/calendView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_below="@+id/header"
    android:layout_marginTop="60dp"
    android:shownWeekCount="5"/>

回答1:


to be frank I didn't find any specific method to do the same.. But you can do it other way round by setting the layout Height to roughly 200dp to 300dp.

<CalendarView
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:id="@+id/calendarView"
    android:layout_gravity="right"
    />

and if you want to limit your calendar to present date here is the code

CalendarView calendarview;
calendarView = (CalendarView)findViewById(R.id.calendarView);
 long a = calendarView.getDate();
    calendarView.setMaxDate(a);



回答2:


//get month and get how many days in current month
Calendar calendar = Calendar.getInstance();
int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
cal.setMaxDate(daysInMonth); 


来源:https://stackoverflow.com/questions/33810905/android-calendarview-show-only-one-month-calendar-at-a-time

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