huangyanbin / smartTable
- вторник, 16 января 2018 г. в 03:15:50
一款android自动生成表格框架---A Android automatically generated table framework
功能介绍
如何使用
- Step 1. 添加 JitPack repository 到你的build文件
allprojects {
repositories {
...
maven { url 'https://www.jitpack.io' }
}
}
- Step 2. 增加依赖
dependencies {
compile 'com.github.huangyanbin:SmartTable:1.5'
}
- 使用表格View
<com.bin.david.form.core.SmartTable
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<String> column1 = new Column<>("姓名", "name");
Column<Integer> column2 = new Column<>("年龄", "age");
Column<Long> column3 = new Column<>("更新时间", "time");
Column<String> column4 = new Column<>("头像", "portrait");
//如果是多层,可以通过.来实现多级查询
Column<String> column5 = new Column<>("班级", "class.className");
//组合列
Column totalColumn1 = new Column("组合列名",column1,column2);
//表格数据 datas是需要填充的数据
final TableData<User> tableData = new TableData<>("表格名",userList,totalColumn1,column3);
//设置数据
table = findViewById(R.id.table);
//table.setZoom(true,3);是否缩放
table.setTableData(tableData);
- 基本方法介绍
Column
构造方法中还有两个参数IFormat<T>
,IDrawFormat<T>
。其中IFormat<T>
是用于格式化显示文字,比如User
对象中有更新时间字段time
时间戳。我们想要显示不同格式,就可以重写该方法。IDrawFormat<T>
是用于显示绘制格式化,比如User
对象中有头像字段portrait
时间戳,就可以使用该方法,框架提供几种IDrawFormat
包括(文字、Bitmap、Resoure图片、图文结合)。
Column
提供了
setAutoCount(boolean isAutoCount)
isReverseSort
setComparator
setCountFormat
OnColumnItemClickListener
TableData
中基本方法
setSortColumn
settitleDrawFormat
setXSequenceFormat
setYSequenceFormat
setShowCount
TableConfig
中基本方法
setContentStyle
setYSequenceStyle
setXSequenceStyle
setColumnTitleStyle
setTableTitleStyle
setCountStyle
setColumnTitleGridStyle
setGridStyle
setVerticalPadding
setHorizontalPadding
setYSequenceBackgroundColor
setXSequenceBackgroundColor
setColumnTitleBackgroundColor
setContentBackgroundColor
setCountBackgroundColor
setFixedYSequence
setFixedXSequence
setFixedTitle
setFixedFirstColumn
//1.4版本取消了setFixedCountRow
写完SmartChart之后,对android 绘图有了进一步的理解。开始了做SmartTable,开始只是一个小demo,经过一星期的上班偷着写,基本完成表格主要功能,本来还有合并等功能,由于后面没有采用,便只做了开始设计功能,已经满足日常需求。
android中使用表格的场景很少,主要屏幕一页放不下,用户体验不好。在实现过程中,尽量做到体验感好些,我感觉通过固定标题和第一行体验最好,所以默认设置固定。当然你可以自己设置。里面还有不少的坑,希望有需要的朋友可以使用它。
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