表格計劃表(支持簡單定製,如: 計劃表顏色定製,單元格大小定製...)

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) {
            }
        });
    }

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章