zoukankan      html  css  js  c++  java
  • MaterialCalendarView使用时遇到的问题

    一、概述

    MaterialCalendarView是一个开源项目。功能强大支持多选、单选、标注等。

    二、问题

    1、其继承自ViewGroup,故与CalendarView半毛钱关系都没有,完全是一个新的类
    2、其子类CalendarDay是经过调整的

    CalendarDay date = new CalendarDay();
    ......
    Log.e(LOG_TAG, "Date选中日期:" + date.getDate().getYear() + "-" + date.getDate().getMonth() + "-" + date.getDate().getDay());
    Log.e(LOG_TAG, "Calendar选中日期:" + date.getCalendar().get(Calendar.YEAR) + "-" + (date.getCalendar().get(Calendar.MONTH) + 1) + "-" + date.getCalendar().get(Calendar.DAY_OF_MONTH));
    

    得到的结果为

    Date选中日期:116-3-6
    Calendar选中日期:2016-4-30
    

    即:

    CalendarDay.getDate().getYear()得到的年份 = 真实年份 - 1900
    CalendarDay.getDate().getMonth()得到的月份 = 真实年份 - 1
    CalendarDay.getDate().getDay()得到的日 = 星期数 - 1
    

    3、关于DayViewDecorator类
    此类为抽象类,定义如下

    /**
     * Decorate Day views with drawables and text manipulation
     */
    public interface DayViewDecorator {
    
        /**
         * Determine if a specific day should be decorated
         *
         * @param day {@linkplain CalendarDay} to possibly decorate
         * @return true if this decorator should be applied to the provided day
         */
        boolean shouldDecorate(CalendarDay day);
    
        /**
         * Set decoration options onto a facade to be applied to all relevant days
         *
         * @param view View to decorate
         */
        void decorate(DayViewFacade view);
    
    }
    

    实际使用时,只需实现上述两个方法即可,例如

    public class EventDecorator implements DayViewDecorator {
    
        private final int color;
        private final HashSet<CalendarDay> dates;
    
        public EventDecorator(int color, Collection<CalendarDay> dates) {
            this.color = color;
            this.dates = new HashSet<>(dates);
        }
    
        @Override
        public boolean shouldDecorate(CalendarDay day) {
            return dates.contains(day);
        }
    
        @Override
        public void decorate(DayViewFacade view) {
            view.addSpan(new DotSpan(5, color));
        }
    }
    
  • 相关阅读:
    URAL 2046 A
    URAL 2056 Scholarship 水题
    Codeforces Gym 100286I iSharp 水题
    Codeforces Gym H. Hell on the Markets 贪心
    Codeforces Gym 100286G Giant Screen 水题
    Codeforces Gym 100286B Blind Walk DFS
    Codeforces Gym 100286F Problem F. Fibonacci System 数位DP
    Codeforces Gym 100286A. Aerodynamics 计算几何 求二维凸包面积
    Codeforces Gym 100418K Cards 暴力打表
    Codeforces Gym 100418J Lucky tickets 数位DP
  • 原文地址:https://www.cnblogs.com/neillee/p/5467621.html
Copyright © 2011-2022 走看看