android 日历仿IOS,基于Android week view仿小米和iphone日历效果

本文介绍了如何在Android中创建一个仿iOS和小米日历的应用,利用Android-week-view库作为起点,实现了日程显示、滑动切换等功能。通过自定义WeekHeaderView和WeekDayView控件,完成界面绘制,并通过Scroller和GestureDetector处理滑动事件。文章还提供了布局文件和关键Java代码示例,包括事件监听和数据填充。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

最近由于项目需求,要做一个仿小米日历的功能,下面显示一天的日程,header以周为单位进行滑动,github上找了很久也没有找到合适的,但找到一相近的开源项目Android-week-view,它不是我们项目所需要的效果,但是它帮我们实现的Event的添加和事件的处理,这让我们省了不少工作,Android-week-view效果如下图

ff92b118472aece5b42310ab9efef169.png

废话不多说,先看看我项目中的效果

4f9a158f48c347f4bb3570f2c6e67c8c.gif

e16e6e629e4c6b932019cc5ec9cee800.gif

主要包括两个核心的类,两个定义控件,上面的WeekHeaderView和下面的WeekDayView,都是继承的view,然后计算位置,将上面的week label 和下面的Day text 画上去,通过Scroller和 GestureDetector控制滑动和处理各种事件。废话不多说,直接教大家怎么用。

首先是布局文件,大家可以通过属性去控件文字的大小,背影颜色、焦点颜色等等。

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

android:id="@+id/tv_date"

android:layout_width="match_parent"

android:layout_height="30dp"

android:background="#455964"

android:gravity="center"

android:text="2015年1月"

android:textColor="#ffffff"

android:textSize="16sp"/>

android:id="@+id/weekheaderview"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@+id/tv_date"

app:firstDayOfWeek2="sunday"

app:headerBackgroundColor="#455964"

app:headerDayLabelNormalTextColor="#ffffff"

app:headerDayLabelTextSize="20sp"

app:headerDayLabelTodayTextColor="@android:color/holo_red_dark"

app:headerFocusBackgroundColor="#ffffff"

app:headerFocusSameDayBackgroundColor="#ffffff"

app:headerFocusSameDayTextColor="#000000"

app:headerFocusTextColor="#000000"

app:headerPaddingTop="20dp"

app:headerRowGap="40dp"

app:headerWeekLabelTextColor="#ffffff"

app:headerWeekLabelTextSize="16sp" />

android:id="@+id/weekdayview"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_below="@+id/weekheaderview"

android:visibility="visible"

app:columnGap="8dp"

app:dayBackgroundColor="#ffffffff"

app:eventTextColor="@android:color/white"

app:headerColumnBackground="#ffffffff"

app:headerColumnPadding="8dp"

app:headerColumnTextColor="@color/toolbar_text"

app:headerRowBackgroundColor="#465a65"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值