之前开发任务中有涉及到年月日日历的切换效果,由于是需要联动,想到的方向大概有3种,要么通过处理view的touch事件,要么是通过自定义behavior去实现,要么是通过ViewDragHelper这个神器去实现,网上比较多的是通过自定义bahavior去实现,本文使用的是第三种方法,实现的是一个可高度定制自由切换的周月日历视图,提供一种思路去实现页面联动效果。
features可以控制是否允许左右滑动,上下滑动,切换年月
流畅的上下周月模式切换
自定义日历样式
基于material-calendarview 这个库实现,可以下载源码根据需求定制效果
Usagesstep 1 : 添加依赖gradle
allprojects {
repositories {
......
maven { url 'https://jitpack.io' }
}
}
dependencies {
......
compile 'com.github.idic779:monthweekmaterialcalendarview:1.5'
}step 2: 添加布局android:id="@+id/slidelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/linearlayout">
android:id="@+id/calendarView_month_mode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:mcv_calendarMode="month"
app:mcv_showOtherDates="other_months