Android Staticlayout text rendering

Source: Internet
Author: User

  • Staticlayout. This is also the use of canvas to draw text, but not using the canvas method.

    Canvas.drawtext () can only draw a single line of text, not line wrapping. It:

    You cannot automatically wrap lines on the edge of a View
  • Taticlayout is constructed by Staticlayout (charsequence source, textpaint paint, int width, layout.alignment align, float spacingmul T, float Spacingadd, Boolean includepad), where the parameters are:

    Widths are the width of the text area, and the text is automatically wrapped when it reaches this width;
    Align is the alignment direction of the text;
    Spacingmult is a multiple of the line spacing, usually fill 1 is good;
    Spacingadd is the additional value of the line spacing, usually fill 0 is good;
    Includeadd refers to whether to add extra space up or down the text to avoid crossing the drawing of some excessively high characters.

    If you need to draw multiple lines of text and do not have too complicated a fancy for the arrangement and style of the text, then use staticlayout.
  •  Textpaint textpaint =new textpaint ();        Textpaint.settextsize (40);        Whether to use pseudo-bold is called Pseudo-bold (fake bold), because it is not by choosing a higher weight font to make the text thicker, but through the program at run time to "stroke" the text.        Textpaint.setfakeboldtext (TRUE);        Whether to underline textpaint.setunderlinetext (true);        Whether to add strikethrough Textpaint.setstrikethrutext (true);        String Text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";        Staticlayout staticlayout = new Staticlayout (text,textpaint,600, Layout.Alignment.ALIGN_NORMAL, 1,0,true);        String Text2 = "A\nbc\ndefghi\njklm\nnopqrst\nuvwx\nyz"; Staticlayout staticLayout2 = new Staticlayout (Text2, Textpaint,, Layout.Alignment.ALIGN_NORMAL, 1, 0, T        Rue);        Canvas.save ();        Canvas.translate (50,100);        Staticlayout.draw (canvas);        Canvas.translate (0,200);        Staticlayout2.draw (canvas); Canvas.restore (); 

Android Staticlayout text drawing

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.