以上是StaticLayoutd 构造方法的介绍,抄过来的,感谢
http://blog.csdn.net/kongbaidepao/article/details/48247217
下面介绍我在项目中是使用吧,
/** * @param context * @return */ static public Boolean printBill(Activity context) { try { int height = 50 + 14 * 30; // 打印高度计算:每多一行加50 Bitmap bitmap = Bitmap .createBitmap(WIDTH, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.WHITE); TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG); paint.setStrokeWidth(1); paint.setColor(Color.BLACK); paint.setTypeface(Typeface.SANS_SERIF); String content = ""; StaticLayout layout; // 打印标题--购物小票 paint.setTextSize(32); content = "备注信息"; layout = new StaticLayout(content, paint, (int) (400), Layout.Alignment.ALIGN_CENTER, 1F, 0, false); canvas.translate(0, 0); layout.draw(canvas); // 分割线 content = "======================\r\n"; layout = new StaticLayout(content, paint, (int) (400), Layout.Alignment.ALIGN_NORMAL, 1F, 0, false); canvas.translate(0, 50); layout.draw(canvas); // 打印客户姓名 content = "客户姓名: " + customerName + "\r\n"; layout = new StaticLayout(content, paint, (int) (400), Layout.Alignment.ALIGN_NORMAL, 1F, 0, false); canvas.translate(0, 50); layout.draw(canvas); // 打印门店名称 content = "门店名称: " + orgName + "\r\n"; layout = new StaticLayout(content, paint, (int) (400), Layout.Alignment.ALIGN_NORMAL, 1F, 0, false); canvas.translate(0, 50); layout.draw(canvas); // 打印款项 content = "款项类型: " + type + "\r\n"; layout = new StaticLayout(content, paint, (int) (400), Layout.Alignment.ALIGN_NORMAL, 1F, 0, false); canvas.translate(0, 50); layout.draw(canvas); // 打印ERP单号 content = "ERP单号: " + erpCode + "\r\n"; layout = new StaticLayout(content, paint, (int) (400), Layout.Alignment.ALIGN_NORMAL, 1F, 0, false); canvas.translate(0, 50); layout.draw(canvas); // 打印HY单号 content = "HY单号: " + jtlOrderNo + "\r\n"; layout = new StaticLayout(content, paint, (int) (400), Layout.Alignment.ALIGN_NORMAL, 1F, 0, false); canvas.translate(0, 50); layout.draw(canvas); canvas.save(Canvas.ALL_SAVE_FLAG); canvas.restore(); String path = Environment.getExternalStorageDirectory() + "/image.png"; System.out.println(path); FileOutputStream os = new FileOutputStream(new File(path)); bitmap.compress(Bitmap.CompressFormat.PNG, 100, os); os.flush(); os.close(); AppHelper.callPrint(context, path); return true; } catch (Exception e) { e.printStackTrace(); return false; } }就这么简单,我也想多说点,可是再说下去说啥呢。我也很绝望啊,可我能怎么办,,,