需求:点击某一行改变背景色
MapTableData tableData = MapTableData.create("测试", tableList);
tableData.setOnRowClickListener(new TableData.OnRowClickListener<Object>() {
@Override
public void onClick(Column column, Object o, int col, int row) {
/**
* 变色
*/
mBinding.table.getConfig().setContentCellBackgroundFormat(new ICellBackgroundFormat<CellInfo>() {
@Override
public void drawBackground(Canvas canvas, Rect rect, CellInfo cellInfo, Paint paint) {
if (cellInfo.row == row) {
paint.setColor(Color.GRAY);
} else {
paint.setColor(Color.WHITE);
}
canvas.drawRect(rect, paint);
mHandler.sendEmptyMessageDelayed(1,200);
}
@Override
public int getTextColor(CellInfo cellInfo) {
return 0;
}
});
}
});
mBinding.table.setTableData(tableData);
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
mHandler.removeMessages(1);
mBinding.table.notifyDataChanged();
super.handleMessage(msg);
}
};
下面是我对表格做的一些配置,仅供参考
mBinding.table.setZoom(true);
mBinding.table.setLongClickable(false);
mBinding.table.getMatrixHelper().setCanZoom(false);//禁止双击放大
mBinding.table.getConfig().setShowXSequence(false);//设置是否显示顶部序号列 setShowXSequence
mBinding.table.getConfig().setShowYSequence(false);//设置是否显示左侧序号列 setShowYSequence
mBinding.table.getConfig().setFixedTitle(true);//固定列标题 setFixedTitle
mBinding.table.getConfig().setShowTableTitle(false);//设置是否显示表格标题 setShowTableTitle
mBinding.table.getConfig().setShowColumnTitle(true);
mBinding.table.getConfig().setFixedYSequence(true);//固定左侧 setFixedYSequence
Column firstColumn = (Column) mBinding.table.getTableData().getColumns().get(0);
Column fiveColumn = (Column) mBinding.table.getTableData().getColumns().get(5);
firstColumn.setFixed(true);
fiveColumn.setFixed(true);
//设置内容文字样式 setContentStyle
FontStyle contentFontStyle = new FontStyle();
contentFontStyle.setTextSize(AppKit.dip2px(13f));
mBinding.table.getConfig().setContentStyle(contentFontStyle);
//设置列标题文字样式 setColumnTitleStyle
FontStyle titleFontStyle = new FontStyle();
titleFontStyle.setTextSize(AppKit.dip2px(14.5f));
titleFontStyle.setTextColor(Color.BLACK);
mBinding.table.getConfig().setColumnTitleStyle(titleFontStyle);
//设置网格行padding setHorizontalPadding
mBinding.table.getConfig().setHorizontalPadding(AppKit.dip2px(2.4f))
.setVerticalPadding(AppKit.dip2px(9.0f));