android动态生成表格数据,GitHub - ngocnd0242/smartTable: 一款android自动生成表格框架---A Android automatically generate...

SmartTable

68747470733a2f2f6a69747061636b2e696f2f762f6875616e6779616e62696e2f736d6172745461626c652e737667

一款android自动生成表格框架

功能介绍

快速配置自动生成表格;

自动计算表格宽高;

表格列标题组合;

表格固定左序列、顶部序列、第一行、列标题、统计行;

自动统计,排序(自定义统计规则);

表格图文、序列号、列标题格式化;

表格各组成背景、文字、网格、padding等配置;

表格批注;

表格内容、列标题点击事件;

缩放模式和滚动模式;

注解模式;

内容多行显示;

分页模式;

首尾动态添加数据;

丰富的格式化;

支持二维数组展示(用于类似日程表,电影选票等)

支持导入excel

表格合并单元

progress.jpg

seat.jpg

视频展示

bg.png

table.gif

5ccbdde7c5514a1b6f7aec4d865010db.gif

如何使用

引用

Step 1. 添加 JitPack repository 到你的build文件

allprojects {

repositories {

...

maven { url 'https://www.jitpack.io' }

}

}

Step 2. 增加依赖

dependencies {

compile 'com.github.huangyanbin:SmartTable:1.6'

}

使用表格View

android:id="@+id/table"

android:layout_width="match_parent"

android:layout_height="match_parent"

/>

- 注解模式

在您需要生成的表格的类增加注解

@SmartTable(name="表名")

在你需要显示的字段增加注解

// id为该字段所在表格排序位置

@SmartColumn(id =1,name = "列名")

//如果需要查询到该成员变量里面去,通过设置type实现

@SmartColumn(type = ColumnType.Child)

设置表格数据

table = findViewById(R.id.table);

table.setData(list);

注解模式就是这么简单,你可以直接运行查看效果了。当然这只是注解基本配置,注解里面还有自动统计,列组合等,如果你想要了解注解更多,请查看demo.

- 基本模式

//普通列

Column column1 = new Column<>("姓名", "name");

Column column2 = new Column<>("年龄", "age");

Column column3 = new Column<>("更新时间", "time");

Column column4 = new Column<>("头像", "portrait");

//如果是多层,可以通过.来实现多级查询

Column column5 = new Column<>("班级", "class.className");

//组合列

Column totalColumn1 = new Column("组合列名",column1,column2);

//表格数据 datas是需要填充的数据

final TableData tableData = new TableData<>("表格名",userList,totalColumn1,column3);

//设置数据

table = findViewById(R.id.table);

//table.setZoom(true,3);是否缩放

table.setTableData(tableData);

- 基本方法介绍

Column构造方法中还有两个参数 IFormat, IDrawFormat。其中IFormat是用于格式化显示文字,比如User对象中有更新时间字段time时间戳。我们想要显示不同格式,就可以重写该方法。IDrawFormat是用于显示绘制格式化,比如User对象中有头像字段portrait时间戳,就可以使用该方法,框架提供几种IDrawFormat包括(文字、Bitmap、Resoure图片、图文结合)。

Column提供了

是否自动排序setAutoCount(boolean isAutoCount)

是否反序排列isReverseSort

设置排序比较setComparator

统计格式化setCountFormat

点击事件OnColumnItemClickListener

TableData中基本方法

设置排序列setSortColumn

2. 设置列标题格式化settitleDrawFormat

3. 设置顶部序列号格式化setXSequenceFormat

4. 设置左边序列号格式化setYSequenceFormat

5. 设置是否显示统计setShowCount

TableConfig中基本方法

设置内容文字样式 setContentStyle

2. 设置左边序列文字样式 setYSequenceStyle

3. 设置顶部序列文字样式 setXSequenceStyle

4. 设置列标题文字样式 setColumnTitleStyle

5. 设置表格标题文字样式 setTableTitleStyle

6. 设置统计行样式 setCountStyle

7. 设置列标题网格样式 setColumnTitleGridStyle

8. 设置表格网格样式 setGridStyle

9. 设置网格列padding setVerticalPadding

10. 设置网格行padding setHorizontalPadding

11. 设置左序列背景 setYSequenceBackgroundColor

12. 设置右序列背景 setXSequenceBackgroundColor

13. 设置列标题背景 setColumnTitleBackgroundColor

14. 设置内容背景 setContentBackgroundColor

15. 设置统计行背景 setCountBackgroundColor

16. 固定左侧 setFixedYSequence

17. 固定顶部 setFixedXSequence

18. 固定列标题 setFixedTitle

19. 固定第一列 setFixedFirstColumn //1.4版本取消了

20. 固定统计行setFixedCountRow

总结

写完SmartChart之后,对android 绘图有了进一步的理解。开始了做SmartTable,开始只是一个小demo,经过一星期的上班偷着写,基本完成表格主要功能,本来还有合并等功能,由于后面没有采用,便只做了开始设计功能,已经满足日常需求。

android中使用表格的场景很少,主要屏幕一页放不下,用户体验不好。在实现过程中,尽量做到体验感好些,我感觉通过固定标题和第一行体验最好,所以默认设置固定。当然你可以自己设置。里面还有不少的坑,希望有需要的朋友可以使用它。

License

SmartTable is released under the Apache 2.0 license.

Copyright 2017 Huangyanbin.

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at following link.

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitat

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值