public Bitmap getNewBitMap(String text) { Bitmap newBitmap = Bitmap.createBitmap(120,150, Config.ARGB_4444); Canvas canvas = new Canvas(newBitmap); canvas.drawBitmap(bmp, 0, 0, null); TextPaint textPaint = new TextPaint(); textPaint.setAntiAlias(true); textPaint.setTextSize(16.0F); StaticLayout sl= new StaticLayout(text, textPaint, newBitmap.getWidth()-8, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false); canvas.translate(6, 40); sl.draw(canvas); return newBitmap; }
Android staticlayout
Staticlayout layout = new staticlayout (context. getstring (R. String. About), textpaint, (INT) (300 * fdensity), alignment. align_center, 1.5f, 0, false );
Layout. Draw (canvas );
Parameter description:
1. String sub-Resource
2. Paint Brush object
3. layout width. The line feed is automatically generated when the string exceeds the width.
4. layout styles: align_center, align_normal, and align_opposite.
5. Relative row spacing, relative font size. 1.5f indicates the font height of the row spacing of 1.5 times.
6. Relative row spacing. 0 indicates 0 pixels.
The actual line spacing is equal to the sum of the two.
7. I still don't know what it means. The parameter name is Boolean includepad.
It should be noted that this layout is drawn on the canvas (0, 0) by default. If you need to adjust the position, you can only move the canvas's starting coordinate before draw.
Canvas. Translate (x, y );