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