An Android library that allows you to build text layouts more easily.
Java Kotlin
Switch branches/tags
Clone or download
xiphirx and facebook-github-bot Prepare next development version
Summary: 1.5.0 is next

Reviewed By: sjkirby

Differential Revision: D8575587

fbshipit-source-id: 91668b882d33f5436176cfeca18719e6549a1a16
Latest commit a0330ea Jun 22, 2018


Build text Layouts easily on Android.


  • Create text Layouts easily.
  • Reuse builders to create similarly styled Layouts.
  • Cache Layouts of commonly used strings.
  • Improve performance by warming up the FreeType cache.


If using Gradle, add this to your build.gradle:

compile 'com.facebook.fbui.textlayoutbuilder:textlayoutbuilder:1.4.0'

or, if using Maven:



  1. Set the properties on the TextLayoutBuilder:
TextLayoutBuilder builder = new TextLayoutBuilder()
    .setText("TextLayoutBuilder makes life easy")
    .setWidth(400 /*, MEASURE_MODE_EXACTLY */);
  1. Call build() on the builder to get a Layout:
Layout layout =;
  1. Use the Layout in your code:
public class CustomView extends View {
    private Layout layout;

    public CustomView(Context context) {

    public void setLayout(Layout layout) {
        this.layout = layout;

    protected void onDraw(Canvas canvas) {

        // Draw the layout.

Additional Usage

  1. Cache the layouts for commonly used strings by turning on caching in the TextLayoutBuilder.
  1. Glyph warming provides significant performance boost for large blurbs of text. Turn this on and pass in a GlyphWarmer for the TextLayoutBuilder.
    .setGlyphWarmer(new GlyphWarmerImpl());
  1. Import a style defined in XML into a TextLayoutBuilder object.
    textLayoutBuilder, // builder object
    context,           // Activity context
    resId);            // style resource id


TextLayoutBuilder is Apache-2-licensed.