让我与您分享一些代码:
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);
}
}
希望它能满足你的需要!