android怎么把表格居中对齐,android – 如何居中对齐PdfPCell中的模板元素

作者在构建月度任务列表时,尝试使用PdfPTable和PdfPCell创建动态大小和颜色的矩形来表示不同严重级别的任务。然而,矩形始终位于左上角而非期望的居中位置。代码中关于定位的部分存在困惑,寻求解决V&H定位问题的方法。
摘要由CSDN通过智能技术生成

我正在建立一个月份的垂直列表,每个月都有一个水平的天数列表.每天我都会添加一个大小有色的矩形;大小和颜色取决于db查询的值.

我正在使用this answer中提供的PdfPTable,PdfPCell和cbCreateTemplate

除了矩形的位置之外,其他一切工作正常(矩形的大小,矩形的颜色):它始终位于0,0即使我(想)我已经设置了V& H定位.下面是代码的摘录;请指教.

int Severity = args.getPLR().get(i).getItems().get(j).getItems().get(itemIndex).getSeverity();

Severity = Severity + 5; //plump up, so that max (10) should fill the cell

PdfPCell cell = new PdfPCell();

cell.setPadding(0);

template = cb.createTemplate(Severity, Severity);

template.setLineWidth(0.5f);

template.rectangle(0, 0, Severity, Severity);

//we should switch the color

//based on the Severity

switch ((Severity-5)) {

case 0:

template.setColorFill(Color.GREEN);

break;

case 1:

template.setColorFill(Color.GREEN);

break;

case 2:

template.setColorFill(Color.YELLOW);

break;

case 3:

template.setColorFill(Color.YELLOW);

break;

case 4:

template.setColorFill(Color.YELLOW);

break;

case 5:

template.setColorFill(Color.ORANGE);

break;

case 6:

template.setColorFill(Color.ORANGE);

break;

case 7:

template.setColorFill(Color.ORANGE);

break;

case 8:

template.setColorFill(Color.RED);

break;

case 9:

template.setColorFill(Color.RED);

break;

case 10:

template.setColorFill(Color.RED);

break;

}

template.fill();

img = Image.getInstance(template);

chunk = new Chunk(img, 0f, 0f);

cell.addElement(chunk);

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

painTable.addCell(cell);

这是显示的图形:

它应该是中心/中心.我哪里出错了?

这是使用已接受的解决方案的更新代码部分:

img = Image.getInstance(template);

chunk = new Chunk(img, 0f, 0f);

Phrase severityChunk = new Phrase(chunk);

PdfPCell cell = new PdfPCell(severityChunk);

cell.setPadding(0);

cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

painTable.addCell(cell);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值