SmartTable使用过程遇到的问题和解决方案

版权声明:转载请注明出处 https://blog.csdn.net/l707941510/article/details/84573135

SmartTable:一款非常强大的类似Excel表格类型Android开源库,功能介绍网上有很多,在这就不介绍功能和如何使用了,

附上项目开源地址:https://github.com/huangyanbin/smartTable

1.当数据不超过一屏时,滑动表格时总计行不显示问题

  在xml文件中设置SmartTable 的布局的高为 wrap_content

2.设置某一列标题样式(背景和文字颜色)和某一列统计行样式(背景和文字颜色)

ICellBackgroundFormat<Column> background = new BaseCellBackgroundFormat<Column>() {
            @Override
            public int getBackGroundColor(Column column) {
                return ContextCompat.getColor(ParBanGongActivity.this, R.color.content_bg);
            }

            @Override
            public int getTextColor(Column column) {
                if("加班".equals(column.getColumnName())){
                    return ContextCompat.getColor(ParBanGongActivity.this, R.color.colorAccent);
                }
                return TableConfig.INVALID_COLOR;
            }
};
//设置列标题背景和颜色
table.getConfig().setColumnCellBackgroundFormat(background);
//设置统计行背景和颜色
table.getConfig().setCountBgCellFormat(background);

如上图,设置“加班列”标题为红色,统计行为红色,内容的颜色可以通过ICellBackgroundFormat<CellInfo>设置,如:

ICellBackgroundFormat<CellInfo> backgroundFormat = new BaseCellBackgroundFormat<CellInfo>() {
            @Override
            public int getBackGroundColor(CellInfo cellInfo) {
                if(cellInfo.row %2 == 0 && cellInfo.col>=2) {
                    return ContextCompat.getColor(ParBanGongActivity.this, R.color.content_bg);
                }
                return TableConfig.INVALID_COLOR;
            }

            @Override
            public int getTextColor(CellInfo cellInfo) {
                if(cellInfo.col>=2 && cellInfo.col%2==1) {
                    return ContextCompat.getColor(ParBanGongActivity.this, R.color.colorAccent);
                }
                return TableConfig.INVALID_COLOR;
            }
        };
table.getConfig().setContentCellBackgroundFormat(backgroundFormat);

3.表头(列标题)换行并限制表头单元格的最大宽度

这个可以参考http://www.jcodecraeer.com/plus/view.php?aid=12153

4.统计行Double值格式化(保留两位小数)

final DecimalFormat df = new DecimalFormat("#0.00");
column.setCountFormat(new DecimalCountFormat() {
    @Override
    public String getCountString() {
        return df.format(getCount());
    }
});

5.单元格Double值格式化(保留两位小数)

final DecimalFormat df = new DecimalFormat("#0.00");
column.setFormat(new IFormat<Double>() {
    @Override
    public String format(Double aDouble) {
        return df.format(aDouble);
    }
});

以上只是本人在使用过程中,项目中遇到的小问题,仅供参考,勿喷!后续遇到新的问题会补充,如果你们发现

有其他问题并已解决可以评论区留言,大家分享一下

猜你喜欢

转载自blog.csdn.net/l707941510/article/details/84573135