i# 簡介
這是一個高仿釘釘和小米的日歷控件,支持快速滑動志衣,界面緩存岳服。想要定制化UI,使用起來非常簡單,就像使用ListView一樣
一些特點:
- 可以自定義日歷控件UI
- 支持快速滑動
- 支持農(nóng)歷和陽歷
- 界面UI緩存和日歷數(shù)據(jù)緩存
- 擴展view支持listView的滑動
- 左右無限滑動
效果
- 先上兩張demo的效果圖典挑,分別是仿小米和釘釘日歷效果圖
仿小米日歷 | 仿釘釘日歷 |
---|---|
- 再看下交互效果
how to use
- Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add the dependency
dependencies {
compile 'com.github.codbking:CalendarExaple:v1.0.0'
}
-
在layout的xml中添加CalendarLayout和CalendarDateView
注意:CalendarDateView一定是CalendarLayout第一個view酥宴,擴展view必須是CalendarDateView第二個view
<com.codbking.calendar.CalendarLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<com.codbking.calendar.CalendarDateView
android:id="@+id/calendarDateView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
/>
</com.codbking.calendar.CalendarLayout>
-
在你的java文件中設(shè)置CalendarDateView的CaledarAdapter和CalendarView.OnItemClickListener監(jiān)聽
注意:想要設(shè)置選中效果,只需設(shè)置CaledarAdapter中的view的選中背景
mCalendarDateView.setAdapter(new CaledarAdapter() {
@Override
public View getView(View convertView, ViewGroup parentView, CalendarBean bean) {
//判斷convertView為null您觉,可以有效利用view的回收重用拙寡,左右滑動的效率高
if (convertView == null) {
convertView = LayoutInflater.from(parentView.getContext()).inflate(R.layout.item_xiaomi, null);
}
TextView chinaText = (TextView) convertView.findViewById(R.id.chinaText);
TextView text = (TextView) convertView.findViewById(R.id.text);
text.setText("" + bean.day);
//mothFlag 0是當(dāng)月,-1是月前琳水,1是月后
if (bean.mothFlag != 0) {
text.setTextColor(0xff9299a1);
} else {
text.setTextColor(0xff444444);
}
chinaText.setText(bean.chinaDay);
return convertView;
}
});
mCalendarDateView.setOnItemClickListener(new CalendarView.OnItemClickListener() {
@Override
public void onItemClick(View view, int postion, CalendarBean bean) {
mTitle.setText(bean.year + "/" + bean.moth + "/" + bean.day);
}
});