Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

怎么单独设置Column的背景 #21

Closed
kingyangcn opened this issue Feb 8, 2018 · 7 comments
Closed

怎么单独设置Column的背景 #21

kingyangcn opened this issue Feb 8, 2018 · 7 comments

Comments

@kingyangcn
Copy link

需求是根据值设置cell的背景,值不为空的cell将其背景设置为红色。代码如下,得到的结果是所有cell都变红色了,并且覆盖了文本值。
`column4.setDrawFormat(new TextDrawFormat() {

        @Override
        public void drawBackground(Canvas c, CellInfo<String> cellInfo, Rect rect, TableConfig config) {
            if (!TextUtils.isEmpty(cellInfo.value)) {
                c.drawColor(Color.RED);
            }
        }
    });`
@huangyanbin
Copy link
Owner

绘制单个 格子背景是
Paint paint = config.getPaint(); paint.setColor(color); paint.setStyle(Paint.Style.FILL); canvas.drawRect(rect, paint);
不是drawColor
你是重写的TextDrawFormat drawBackground方法,其实有专门设置背景的和改变字体颜色的。
table.getConfig().setContentBackgroundFormat(new BaseCellBackgroundFormat() {
@OverRide
public int getBackGroundColor(CellInfo cellInfo) {

            //根据cellInfo.column需要返回不同背景颜色
            return TableConfig.INVALID_COLOR;
        }

        @Override
        public int getTextColor(CellInfo cellInfo) {
            //根据cellInfo.column需要返回不同字体颜色
            return TableConfig.INVALID_COLOR;
        }
    });

@kingyangcn
Copy link
Author

@huangyanbin 如果要绘制自定义背景该怎么写呢?

@huangyanbin
Copy link
Owner

如果你想要绘制圆形或者其他,你可以使用table.getConfig().setContentBackgroundFormat(ICellBackgroundFormat),重新接口方法就可以,可定制自己想要的背景效果,其实BaseCellBackgroundFormat就是个绘制Rect的实现类。

@kingyangcn
Copy link
Author

知道了,之前也看到这个方法了,没发现可以通过cell.column得到列的信息,以为只能对所有列统一处理。感谢

@kingyangcn
Copy link
Author

@huangyanbin BaseCellBackgroundFormat只有getBackGroundColor,没有getBackGroundDrawable之类的,要怎么实现呢

@huangyanbin
Copy link
Owner

你想要绘制图片之类的,必须用实现ICellBackgroundFormat接口,然后自己绘制图片,绘制图片很简单,网上一大堆。

@kingyangcn
Copy link
Author

好的。真是太感谢了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants