monthweekmaterialcalendarview

项目地址:idic779/monthweekmaterialcalendarview 

简介:纵享丝滑滑动切换的周月日历,可流畅滑动高度定制,仿小米日历,基于 material-calendarview (Android 官方的 CalendarView)实现,简洁高效

更多:作者   提 Bug

标签:

apk download

觉得有帮助的可以给个 star,有问题联系 idic779@163.com QQ 290950778,有定制问题直接提 issue

   

可以点击进去查看实现过程 纵享丝滑滑动切换的周月日历,水滴效果,丰富自定义日历样式,仿小米日历

之前开发任务中有涉及到年月日日历的切换效果,由于是需要联动,想到的方向大概有 3 种,要么通过处理 view 的 touch 事件,要么是通过自定义 behavior 去实现,要么是通过 ViewDragHelper 这个神器去实现,网上比较多的是通过自定义 bahavior 去实现,本文使用的是第三种方法,实现的是一个可高度定制自由切换的周月日历视图,提供一种思路去实现页面联动效果。

features

  • 可以控制是否允许左右滑动,上下滑动,切换年月
  • 流畅的上下周月模式切换
  • 允许选择农历和普通日历
  • 丰富自定义日历样式
  • 设置每周的第一天
  • 设置某一天不允许选中
  • 基于 material-calendarview 这个库实现,可以下载源码根据需求定制效果

    更新日志

    V1.7

    支持 grid and staggeredgrid layoutManager

Usages

step 1 : 添加依赖

gradle
allprojects {repositories {......maven { url 'https://jitpack.io' }}
}dependencies {......compile 'com.github.idic779:monthweekmaterialcalendarview:1.7'
}

step 2: 添加布局

  <com.amy.monthweek.materialcalendarview.MonthWeekMaterialCalendarViewandroid:id="@+id/slidelayout"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_below="@+id/linearlayout"><com.prolificinteractive.materialcalendarview.MaterialCalendarViewandroid:id="@+id/calendarView_month_mode"android:layout_width="match_parent"android:layout_height="wrap_content"app:mcv_calendarMode="month"app:mcv_showOtherDates="other_months"app:mcv_showWeekView="false" /><com.prolificinteractive.materialcalendarview.MaterialCalendarViewandroid:id="@+id/calendarView_week_mode"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@android:color/white"android:visibility="invisible"app:mcv_calendarMode="week"app:mcv_showTopBar="false"app:mcv_showWeekView="false" /><android.support.v7.widget.RecyclerViewandroid:id="@+id/recyclerView"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@android:color/white"android:orientation="vertical" /><LinearLayoutandroid:id="@+id/weekview_top"android:layout_width="match_parent"android:layout_height="44dp"android:background="@color/colorPrimary"android:orientation="horizontal"><TextViewandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:text="周日" /><TextViewandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:text="周一" /><TextViewandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:text="周二" /><TextViewandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:text="周三" /><TextViewandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:text="周四" /><TextViewandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:text="周五" /><TextViewandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:text="周六" /></LinearLayout></com.amy.monthweek.materialcalendarview.MonthWeekMaterialCalendarView>

step 3: 如何使用

  • 底部的 recyclerView 的 layoutManager 要实现 ILayoutManager 接口,设置是否允许上下滑动, 例如示例中的CustomLinearLayoutManager.java

设置当前日期,日历才会滚动到对应日期

monthWeekMaterialCalendarView.setCurrentDate(selectedDate);

设置选中日期

monthWeekMaterialCalendarView.setSelectedDate(selectedDate)

添加日历的样式,例如红点 或者自定义图案

monthWeekMaterialCalendarView.addDecorator(new EventDecorator(Color.RED, dates))

移除日历样式

monthWeekMaterialCalendarView.removeDecorators();

设置当前的模式

monthWeekMaterialCalendarView.setMode(MonthWeekMaterialCalendarView.Mode.MONTH)

跳转到上一个月

monthWeekMaterialCalendarView.goToPrevious();

跳转到下个月

monthWeekMaterialCalendarView.goToNext();

设置是否允许竖直拖动,默认是允许拖动切换周月模式

monthWeekMaterialCalendarView.setCanDrag

设置是否允许左右滑动

monthWeekMaterialCalendarView.setPagingEnabled

添加选中日期、模式改变 或者月份改变的回调

    monthWeekMaterialCalendarView.state().edit()//设置最大最小日期.setMinimumDate(new CalendarDay(2017,1,1)).setMaximumDate(new CalendarDay(2018,3,1)).setSlideModeChangeListener(new MonthWeekMaterialCalendarView.SlideModeChangeListener() {@Overridepublic void modeChange(MonthWeekMaterialCalendarView.Mode mode) {}}).setSlideDateSelectedlistener(new MonthWeekMaterialCalendarView.SlideDateSelectedlistener() {@Overridepublic void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {}}).setSlideOnMonthChangedListener(new MonthWeekMaterialCalendarView.SlideOnMonthChangedListener() {@Overridepublic void onMonthChanged(MaterialCalendarView widget, CalendarDay date) {}}).commit();

设置选中颜色

monthWeekMaterialCalendarView.setSelectionColor
因为基于 MaterialCalendarView 的周和月视图组成的,所以可以在 XML 中设置选中颜色,字体样式等等
       <com.prolificinteractive.materialcalendarview.MaterialCalendarViewandroid:id="@+id/calendarView_month_mode"android:layout_width="match_parent"android:layout_height="wrap_content"app:mcv_selectionColor="@color/colorPrimary"app:mcv_dateTextAppearance="@style/TextAppearance.MaterialCalendarWidget.Date"app:mcv_calendarMode="month"app:mcv_showOtherDates="defaults|other_months"app:mcv_showWeekView="false" /><com.prolificinteractive.materialcalendarview.MaterialCalendarViewandroid:id="@+id/calendarView_week_mode"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@android:color/white"android:visibility="invisible"app:mcv_selectionColor="@color/colorPrimary"app:mcv_dateTextAppearance="@style/TextAppearance.MaterialCalendarWidget.Date"app:mcv_calendarMode="week"app:mcv_showTopBar="false"app:mcv_showWeekView="false" />

定制用法

如果你想给单独的日期视图设置一些样式的话,例如周末右上角有个图标这样子的需求之类的话,你可以写一个类继承自 DayViewDecorator

public class RemindDecorator implements DayViewDecorator {private final Calendar calendar = Calendar.getInstance();private Context context;public RemindDecorator(Context context) {this.context=context;}@Overridepublic boolean shouldDecorate(CalendarDay day) {day.copyTo(calendar);int weekDay = calendar.get(Calendar.DAY_OF_WEEK);return weekDay == Calendar.SATURDAY || weekDay == Calendar.SUNDAY;}@Overridepublic void decorate(DayViewFacade view) {view.addSpan(new RestSpan(context));}
}
  • shouldDecorate()这个方法是判断是否需要添加 Decorator 的条件
  • decorate()这个方法可以对显示样式做一些操作

DayViewFacade 可以通过 setSelectionDrawable(),setBackgroundDrawable(),addSpan()设置样式,尤其是 addSpan 的方法,因为你传进去的是一个 span,所以你可以在里面做很多自定义样式的操作,例如RestSpan.java周末右上角加个图标。

还可以怎么用

  接下来说下你可以怎么去定制?如果你想替换项目中的月和周视图的话,很简单,只需要你自己的周月视图必须有一个方法获得单行日历的高度(例如我的库中的 MaterialCalendarView.getItemHeight() ),然后把这个月视图和周视图,分别在 MonthWeekMaterialCalendarView 里面按照顺序放到对应位置即可。然后再 setListener()里面设置相关的回调处理,例如日期选中或者月份切换的回调等。更多的使用方法可以下载 demo 参考

License

Copyright 2018 amyLicensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

纵享丝滑滑动切换的周月日历,可流畅滑动高度定制,仿小米日历,基于 material-calendarview相关推荐

  1. 纵享丝滑滑动切换的周月日历,水滴效果,丰富自定义日历样式,仿小米日历(ViewDragHelper实现)...

    本文已授权微信公众号:鸿洋(hongyangAndroid)在微信公众号平台原创首发 老规矩先贴效果图 github地址,觉得有帮助的可以给个 star 呗 github.com/idic779/mo ...

  2. 纵享丝滑滑动切换的周月日历,水滴效果,丰富自定义日历样式

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QF0ojEiz-1650020556182)(https://user-gold-cdn.xitu.io/2018/2/ ...

  3. android 涂鸦 卡顿,涂鸦框架的优化——解决绘制时的卡顿问题,纵享丝滑

    前言 V5.5: 增加优化绘制的选项,可优化绘制速度和性能,纵享丝滑. boolean optimizeDrawing = true; // 是否优化绘制,建议开启,可优化绘制速度和性能. Doodl ...

  4. typora+picgo+gitee搭建免费图床纵享丝滑

    typora+picgo+gitee搭建免费图床纵享丝滑 0.写在前面 由于之前自己在github搭了自己的博客,伴随之而来的一系列问题.如github不显示图片,github图床加载太慢等一系列问题 ...

  5. 让你的小米5纵享丝滑,可能是最快的小米5rom

    小米5刷原生7.1.1 ROM.配合xposed框架模块,非常的流畅!用纵享丝滑形容真不为过. 此标题是根据我的多次刷机实践得来的结果.话不多说先上几张GIF. 下面我上资源和教程: 首先手机要解锁刷 ...

  6. android 仿小米日历 周视图 月视图切换

    android 仿小米日历,周视图左右滑动,月视图左右滑动,周视图月视图无缝切换: http://download.csdn.net/detail/chen352602412/9556162 插播广告 ...

  7. 阿里云数据库专家白宸:Redis带你尽享丝滑!(图灵访谈)

    访谈嘉宾: 本名郑明杭,现阿里云NoSQL数据库技术专家.先后从事Tair分布式系统.Memcached云服务及阿里云Redis数据库云服务开发,关注分布式系统及NoSQL存储技术前沿. 作为嘉宾,曾 ...

  8. 【达摩院OpenVI】几行代码,尽享丝滑视频观感

    团队模型.论文.博文.直播合集,点击此处浏览 随着网络电视.手机等新媒体领域的快速发展,用户对于观看视频质量的要求也越来越高.当前市面上所广为传播的视频帧率大多仍然处于20-30fps,已经无法满足用 ...

  9. 阿里云数据库专家白宸:Redis带你尽享丝滑!

    本文仅用于学习和交流目的,不得用于商业目的.非商业转载请注明作译者.出处,并保留本文的原始链接:http://www.ituring.com.cn/art... 访谈嘉宾: 本名郑明杭,现阿里云NoS ...

最新文章

  1. 剑指offer:面试题18. 删除链表的节点
  2. 给Python的类和对象动态增加属性和方法
  3. Nginx_环境搭建
  4. CF--思维练习--CodeForces - 220C Little Elephant and Shifts (STL模拟)
  5. 使用ACME部署生成阿里云免费HTTPS证书
  6. MySQL高级之事务
  7. python zip用法_Python zip()用法及代码示例
  8. python从入门到精通pdf百度云-跟老齐学Python:从入门到精通 完整版PDF[7MB]
  9. window常用的『运行』命令
  10. 《图解HTTP》阅读笔记--第六章--HTTP首部
  11. 数据仓库的分层,你知道吗?
  12. 联想交换机服务器型号,ThinkSystem DB610s光纤交换机
  13. 【数据处理】Python matplotlib绘制双柱状图以及绘制堆积柱状图——保姆级教程
  14. ITIL 4 Foundation 思维导图笔记整理
  15. 移动优先和桌面优先的状态
  16. 无人机飞控技术-市场现状及未来发展趋势
  17. uni-app学习(四):带有下划线的标签选择
  18. 春风十里不如Node中的一股清流
  19. html5微信页面制作,微信上的html5页面是怎么制作出来的?自己怎么制作微信网页链接?...
  20. 基于 Docker 的 Slurm 作业管理系统

热门文章

  1. Android Paint 抗锯齿画线模糊
  2. 2016年港澳台研究生招生考试报名注意事项
  3. css-summarize
  4. 极客头条微信公众号开通,欢迎关注
  5. 人工智能------概述
  6. mysql日期减7天_Mysql 时间操作(当天,昨天,7天,30天,半年,全年,季度)
  7. 计算机科学作业ppt百度云,ted演讲合集百度云.docx
  8. FISCO-BCOS学习——单群组4节点联盟链、控制台 搭建
  9. Linux加密解压缩-zip-tar
  10. 2022年8月国内外数据库排名