An Android library that allows you to build text layouts more easily.
Latest commit d330d06 Dec 27, 2016 @ahmedre ahmedre committed with facebook-github-bot Fix a mistake in TextLayoutBuilder's README
@public This fixes #6 by fixing the README file, in which
`super.draw()` was placed instead of `super.onDraw()`.

Reviewed By: sriramramani

Differential Revision: D4366906

fbshipit-source-id: 3fc283545b8bc8d1fb9bbfa9e592a252273b5d46


Build text Layouts easily on Android.

TextLayoutBuilder logo


  • 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.0.0'

or, if using Maven:



  1. Set the properties on the TextLayoutBuilder:

    TextLayoutBuilder builder = new TextLayoutBuilder()
        .setTextAppearance(context, resId)
        .setText("TextLayoutBuilder makes life easy")
        .setWidth(400 /*, MEASURE_MODE_EXACTLY */);
  2. Call build() on the builder to get a Layout:

    Layout layout =;
  3. Use the Layout in your code:

    public class CustomView extends View {
        private Layout mLayout;
        public CustomView(Context context, AttributeSet attrs) {
            super(context, attrs);
        public void setLayout(Layout layout) {
            mLayout = 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.

  2. 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());
  3. Import a style defined in XML into a TextLayoutBuilder object.

        mTextLayoutBuilder, // builder object
        mContext,           // Activity context
        resId);             // style resource id