2014-01-14 162 views
0

如何實現我的文本標籤付款的同一行對齊方式左對齊並將其值對齊? 這是我的代碼。有沒有bixolon SPP-R300 SDK的功能,我該如何實現它。謝謝。Android:使用Bixolon熱敏打印機(SPP-R300)打印對齊

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); 

回答

0

讓我跟大家分享一些代碼:

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); 
    } 
} 

希望它適合你需要的東西!