CourseTableView

前言


最近在学习课程表的制作方法,并没有发现一些已经封装好的课表开源库,于是突发奇想封装了一个这样的课程表控件,正好也学习了如果发布自己的第三方库。

项目的地址:CourseTableView
推荐阅读:教你自己写Android第三方库

介绍


CourseTableView 是一个让你快速方便的创建课程表视图的库

CourseTableView.png

平台要求


  • Android SDK 15+

基本使用


  1. 在你的配置文件中添加 JitPack的代码仓库
  • Gradle
    Add it in your root build.gradle at the end of repositories:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  • Maven
<repositories>
    <repository>
       <id>jitpack.io</id>
       <url>https://jitpack.io</url>
    </repository>
</repositories>
  1. 添加依赖
  • Gradle
dependencies {
    compile 'com.github.YueYongDev:CourseTableView:v1.0'
}
  • Maven
<dependency>
    <groupId>com.github.YueYongDev</groupId>
    <artifactId>CourseTableView</artifactId>
    <version>v1.0</version>
</dependency>
  1. 在你想要展示你的课程表的那个界面添加“CourseTableView”
<cn.lyy.coursetable.CourseTableView
    android:id="@+id/ctv"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
  1. 同时,你需要在Activity中创建Course对象
Course c1 = new Course();
c1.setDay(1);
c1.setDes("第一节课");
c1.setJieci(1);
c1.setBg_Color(color[2]);

Course c2 = new Course();
c2.setDay(6);
c2.setDes("第一节课");
c2.setJieci(3);
c2.setBg_Color(color[3]);
  1. 创建一个集合,并把之前创建的对象添加进去
List<Course> list = new ArrayList<>();
list.add(c1);
list.add(c2);
  1. 初始化你的 coursetableview 并且执行 updateCourseViews 方法
CourseTableView courseTableView = (CourseTableView) findViewById(R.id.ctv);
courseTableView.updateCourseViews(list);

扩展


更改课程背景

你可以使用以下的预置背景:

private int color[] = {
        R.drawable.course_info_blue,
        R.drawable.course_info_brown,
        R.drawable.course_info_cyan,
        R.drawable.course_info_deep_orange,
        R.drawable.course_info_deep_purple,
        R.drawable.course_info_green,
        R.drawable.course_info_indigo,
        R.drawable.course_info_light_blue,
        R.drawable.course_info_light_green,
        R.drawable.course_info_lime,
        R.drawable.course_info_orange,
        R.drawable.course_info_pink,
        R.drawable.course_info_purple,
        R.drawable.course_info_red,
        R.drawable.course_info_teal,
        R.drawable.course_info_yellow
    };

也可以选择自定义你的背景:

  1. 创建一个 Drawable resource file.

bg_resource.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
        <solid android:color="#A5D6A7" />
        <corners android:radius="5dp" /> 
</shape>
  1. 使用这个资源文件作为背景
int bg_resource = R.drawable.bg_resource;
c3.setBg_Color(bg_resource);

使课表可以点击

执行以下方法便可以响应点击事件

courseTableView.setOnCourseItemClickListener(new CourseTableView.OnCourseItemClickListener() {
    @Override
    public void onCourseItemClick(TextView tv, int jieci, int day, String des) {
        String string = tv.getText().toString();
        Toast.makeText(getApplicationContext(), string, Toast.LENGTH_SHORT).show();
    }
});

用法例子详见Demo

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,837评论 18 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,860评论 25 708
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,925评论 6 342
  • 家住龙泽,上地上班,每天坐公交车都堵在西二旗,二三四五勉强可以接受,周一实在忍无可忍!地铁堵人,公交堵车,大...
    朱大爷阅读 325评论 0 1