有哪个网站可以做兼职,网站建设属于技术活吗,磁力棒,网站设计的意义愿你出走半生,归来仍是少年#xff01; 环境#xff1a;Android Studio 在android上进行统计数据、列表、表格数据等信息展示是常有的需求。 在Github上有一个优秀的控件#xff1a;smartTable
1.功能介绍 快速配置自动生成表格#xff1b;自动计算表格宽高#xff1b;表… 愿你出走半生,归来仍是少年 环境Android Studio 在android上进行统计数据、列表、表格数据等信息展示是常有的需求。 在Github上有一个优秀的控件smartTable
1.功能介绍 快速配置自动生成表格自动计算表格宽高表格列标题组合表格固定左序列、顶部序列、第一行、列标题、统计行自动统计排序自定义统计规则表格图文、序列号、列标题格式化表格各组成背景、文字、网格、padding等配置表格批注表格内容、列标题点击事件缩放模式和滚动模式注解模式内容多行显示分页模式首尾动态添加数据;丰富的格式化;支持二维数组展示用于类似日程表电影选票等导入excel(支持颜色字体背景批注对齐图片等基本Excel属性)表格合并单元(支持注解合并支持自动合并)支持其他刷新框架SmartRefreshLayout可配置表格最小宽度(小于该宽度自动适配)支持直接List或数组字段转列支持Json数据直接转换成表格支持表格网格指定行列显示支持自动生成表单。 2.如何引入 allprojects { repositories { ... maven { url https://www.jitpack.io } } } dependencies { compile com.github.huangyanbin:SmartTable:2.2.0 } 3.使用
3.1.布局 在布局文件中直接插入控件如下 com.bin.david.form.core.SmartTableandroid:idid/tbandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentapp:layout_constraintBottom_toBottomOfparentandroid:layout_marginTopdimen/popup_title_heightandroid:layout_marginBottomdimen/dp68app:layout_constraintBottom_toTopOfid/llytBtnsapp:layout_constraintTop_toBottomOfid/lytTitle/ 在SmartTable中数据的构建分为两种一种是通过注解模式直接构建方便快捷一种是通过自己代码构建这中扩展性更强。
3.1.通过注解模式构建数据 注解模式是通过在需要生成表格的类增加注记然后通过这个类的集合去填充表格的方式。
3.1.1.SmartTable SmartTable是表格注解用于添加到类上面。它包含了四个参数。
注解作用name表格名count是否显示统计行pageSize页数量currentPage当前页 3.1.2.SmartColumn SmartColumn是列注解用于添加到类的属性上面。它包含了多个参数。
注解作用name列标题id列排序位置(越小越在前面)parent父列名称(不设置则没有父列)align设置该列对齐方式默认居中type设置是否查询下一级。有ColumnType.Own,ColumnType.Child,两个值可以设置假设UserInfo 有个属性是Family family对象你想解析faily对象的属性monther,father两个属性则需要设置Child并在monther,father下添加相对应的注解SmartColumn否则只解析到Family默认是Own。autoMerge设置是否自动合并。假设你返回的数据格式化之后该列附近数据有相同则会自动合并成一个单元格默认不开启合并。maxMergeCount合并最大数量autoCount是否开启统计。 table 开启显示统计行设置autoCount为true则该列可以自动统计默认为false。fixed是否固定该列。 fixed设置为true该列滚动到最左边时可以自动固定住。 3.1.3.示例 SmartTable(count true)
public class WorkloadStatisticItemDto {public LocalDateTime Date;public LocalDateTime getDate(){return Date;}SmartColumn(name 日期,id 1 )public String DataStr;SmartColumn(name 数量个,id 2,autoCount true )public int PointCount0;SmartColumn(name 长度米,id 3,autoCount true )public Double LineLength0d;} 上方是一个注解类包含三列日期、管点数个、管线长米然后通过如下的方式将这个注解类的集合赋予表格控件即可实现展示。 ListWorkloadStatisticItemDto dtos items.values().stream().sorted(Comparator.comparing(WorkloadStatisticItemDto::getDate)).collect(Collectors.toList());binding.tb.setData(dtos); 展示效果 3.2.通过代码组装数据 代码组装数据的时候需要的创建两个类别的东西一个就是数据Dto集合也就是要展示的数据另外一个就是表格的列集合。
3.2.1.列Column 通过查看源码Column有多个构造函数 /**列构造方法* 用于构造组合列* param columnName 列名* param children 子列*/public Column(String columnName, ListColumn children) {this.columnName columnName;this.children children;isParent true;}/**列构造方法* 用于构造组合列* param columnName 列名* param children 子列*/public Column(String columnName, Column... children) {this(columnName, Arrays.asList(children));}/**列构造方法* 用于构造子列* param columnName 列名* param fieldName 需要解析的反射字段*/public Column(String columnName, String fieldName) {this(columnName, fieldName, null, null);}/**列构造方法* 用于构造子列* param columnName 列名* param fieldName 需要解析的反射字段* param format 文字格式化*/public Column(String columnName, String fieldName, IFormatT format) {this(columnName, fieldName, format, null);}/**列构造方法* 用于构造子列* param columnName 列名* param fieldName 需要解析的反射字段* param drawFormat 绘制格式化*/public Column(String columnName, String fieldName, IDrawFormatT drawFormat) {this(columnName, fieldName, null, drawFormat);}/**列构造方法* 用于构造子列* param columnName 列名* param fieldName 需要解析的反射字段* param format 文字格式化* param drawFormat 绘制格式化*/public Column(String columnName, String fieldName, IFormatT format, IDrawFormatT drawFormat) {this.columnName columnName;this.format format;this.fieldName fieldName;this.drawFormat drawFormat;datas new ArrayList();}通过构造创建列并设置其基础属性 ColumnString typeNameCol new Column(大类, TypeName);typeNameCol.setFixed(true);typeNameCol.setAutoMerge(true);ColumnString categoryCol new Column(管类, CategoryName);categoryCol.setFixed(true);ColumnString defaultColorCol new Column(颜色, DefailtColorStr); 3.2.2.表数据TableData 创建数据绑定数据。 var tbData new TableData(管类, dtos, typeNameCol, categoryCol, codeCol, enableCol, nextSurveyIndexCol, defaultColorCol, showDirectionCol, canReverseCol,isDrainageCol);binding.tbCategorys.setTableData(tbData);3.2.3.示例 效果示例 4.总结 SmartTable的表格数据分为两种方式创建注解、代码组装。 若是简单的需求例如表格基础呈现这种需求使用注解是代码量最少、最方便的方式。