How is StaticLayout used in Android? : <p>I need to build my own custom <code>TextView</code> so I have been learning about <code>StaticLayout</code> to draw text on a canvas. This is preferable to using <code>Canvas.drawText()</code> directly, or so the <a href="https://developer.android.com/reference/android/text/StaticLayout.html" rel="noreferrer">documentation</a> says. However, the documentation doesn't give any examples for how do it. There is only a vague reference to <a href="https://developer.android.com/reference/android/text/StaticLayout.Builder.html" rel="noreferrer"><code>StaticLayout.Builder</code></a> being the newer way to do it.</p>

<p>I found an example <a href="http://ivankocijan.xyz/android-drawing-multiline-text-on-canvas/" rel="noreferrer">here</a> but it seems a little dated.</p>

<p>I finally worked though how to do it so I am adding my explanation below.</p>
