Android bitmap automatically draws text line breaks

Source: Internet
Author: User
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 );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.