1

我如何实现我的文本标签的相同行对齐以左对齐并且它的值右对齐?这是我的代码。bixolon SPP-R300 的 SDK 中是否有一个功能,我该如何实现它。谢谢。

 JPOSprinting.mBixolonPrinter.printText("TOTAL AMOUNT PAID",alignmentLeft , textAttributeNormal, BixolonPrinter.TEXT_SIZE_HORIZONTAL1, false);
 JPOSprinting.mBixolonPrinter.printText(AmtPd +"\n", alignmentRight,textAttributeNormal, BixolonPrinter.TEXT_SIZE_HORIZONTAL1, false);
4

1 回答 1

1

让我与您分享一些代码:

private final int LINE_CHARS = 42;

private void printTextColumns(String leftText, String rightText) {
    if (leftText.length() + rightText.length() + 1 > LINE_CHARS) { // If two Strings cannot fit in same line
        int alignment = BixolonPrinter.ALIGNMENT_LEFT;
        int attribute = 0;
        attribute |= BixolonPrinter.TEXT_ATTRIBUTE_FONT_C;
        bixolonPrinter.printText(leftText, alignment, attribute, BixolonPrinter.TEXT_SIZE_HORIZONTAL1, false);

        alignment = BixolonPrinter.ALIGNMENT_RIGHT;
        attribute = 0;
        attribute |= BixolonPrinter.TEXT_ATTRIBUTE_FONT_C;
        bixolonPrinter.printText(rightText, alignment, attribute, BixolonPrinter.TEXT_SIZE_HORIZONTAL1, false);
    } else {
        int padding = LINE_CHARS - leftText.length() - rightText.length();
        String paddingChar = " ";
        for (int i = 0; i < padding; i++) {
            paddingChar = paddingChar.concat(" ");
        }

        int alignment = BixolonPrinter.ALIGNMENT_LEFT;
        int attribute = 0;
        attribute |= BixolonPrinter.TEXT_ATTRIBUTE_FONT_C;
        bixolonPrinter.printText(leftText + paddingChar + rightText, alignment, attribute, BixolonPrinter.TEXT_SIZE_HORIZONTAL1, false);
    }
}

希望它能满足你的需要!

于 2014-06-13T20:54:59.963 回答