public VCalendarView(@NonNull Context context) {
super(context);
}
public VCalendarView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
TypedArray array = context.obtainStyledAttributes(attrs, com.haibin.calendarview.R.styleable.CalendarView);
mMinYear = array.getInt(com.haibin.calendarview.R.styleable.CalendarView_min_year, 2010);
mMaxYear = array.getInt(com.haibin.calendarview.R.styleable.CalendarView_max_year, 2050);
if (mMinYear <= 1900) mMaxYear = 1900;
if (mMaxYear >= 2099) mMaxYear = 2099;
try {
Field field = getClass().getSuperclass().getDeclaredField("mViewPager");
field.setAccessible(true);
mViewPager = (WrapViewPager) field.get(this);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
selectCalendar = super.getSelectedCalendar();
}
/**
* 滚动到某月
*
* @param year
* @param month
*/
public void scrollToMonth(int year, int month) {
mViewPager.setCurrentItem(12 * (year - mMinYear) + month - 1);
}