github地址:https://github.com/PPQingZhao/ScheduleViewDemo
运行截图:
第一张图展示 AM 00:00 - 11:59计划
第二张图展示 PM 00:00 - 11:59计划(经过双指滚动)
这是一个表格形式的计划表
支持单指滑动制定计划,
双指滚动计划表,
支持简单定制,比如: 计划表颜色定制,自定义单元格大小.
使用:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
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">
<com.pp.scheduleviewdemo.widget.ScheduleExcelView
android:id="@+id/main_schedule"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="4dp"
app:columTitleBackground="@color/colorPrimary"
app:columTitleTextColor="@color/white"
app:columTitleTextSize="13sp"
app:dividerColor="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lineColor="@color/colorPrimary"
app:rowTitleTextColor="@color/colorPrimary"
app:rowTitleTextSize="10dp"
app:spanPercent="0.6" />
</android.support.constraint.ConstraintLayout>
private void setupScheduleView() {
// 设置横向标题 (日期:总共7列 S, M, T, W, T, F, S)
String[] week = getResources().getStringArray(R.array.Week);
mSchedule.clearColumTitle();
for (String weekDay : week) {
mSchedule.addColumTitle(weekDay);
}
// 设置纵向标题 (时间: 总共48行,00:00, 00:30, 01:00, ...)
mSchedule.clearRowTitle();
String[] amHour = getResources().getStringArray(R.array.AMHalfHour);
for (int i = 0; i < amHour.length; i++) {
String hour = amHour[i];
ScheduleExcelView.ExcelTitle excelTitle = mSchedule.newTitle()
.setTitle(hour);
if (i == 0) {
excelTitle.setTextSize(8)
.setTextColor(R.color.colorPrimaryDark)
.setDivider(true)
.setDividerColor(R.color.colorPrimaryDark);
}
mSchedule.addRowTitle(excelTitle);
}
String[] pmHour = getResources().getStringArray(R.array.PMHalfHour);
for (int i = 0; i < pmHour.length; i++) {
String hour = pmHour[i];
ScheduleExcelView.ExcelTitle excelTitle = mSchedule.newTitle()
.setTitle(hour);
if (i == 0) {
excelTitle.setTextSize(8)
.setTextColor(R.color.colorPrimaryDark).setDivider(true)
.setDividerColor(R.color.colorPrimaryDark);
}
mSchedule.addRowTitle(excelTitle);
}
// 设置单元格大小
mSchedule.setSpanSize(new ScheduleExcelView.SpanSize() {
@Override
public float getSpanWidth(ScheduleExcelView view, int columCount) {
return view.getExcelWidth() / columCount;
}
@Override
public float getSpanHeight(ScheduleExcelView view, int rowCount) {
return view.getExcelHeight() / (view.getSpanRowCount() * 0.5f + 1);
}
});
mSchedule.setScheduleColor(Color.BLUE);
mSchedule.commit();
// 计划变化监听
mSchedule.setOnScheduleChangeListener(new ScheduleExcelView.OnScheduleChangeListener() {
@Override
public void onScheduleChange(int[][] schedule) {
}
});
}