TextLayoutBuilder

Better way to create text Layouts on Android

License

License

GroupId

GroupId

com.facebook.fbui.textlayoutbuilder
ArtifactId

ArtifactId

textlayoutbuilder
Last Version

Last Version

1.6.0
Release Date

Release Date

Type

Type

aar
Description

Description

TextLayoutBuilder
Better way to create text Layouts on Android
Project URL

Project URL

https://github.com/facebook/TextLayoutBuilder
Source Code Management

Source Code Management

https://github.com/facebook/TextLayoutBuilder.git

Download textlayoutbuilder

How to add to project

<!-- https://jarcasting.com/artifacts/com.facebook.fbui.textlayoutbuilder/textlayoutbuilder/ -->
<dependency>
    <groupId>com.facebook.fbui.textlayoutbuilder</groupId>
    <artifactId>textlayoutbuilder</artifactId>
    <version>1.6.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.facebook.fbui.textlayoutbuilder/textlayoutbuilder/
implementation 'com.facebook.fbui.textlayoutbuilder:textlayoutbuilder:1.6.0'
// https://jarcasting.com/artifacts/com.facebook.fbui.textlayoutbuilder/textlayoutbuilder/
implementation ("com.facebook.fbui.textlayoutbuilder:textlayoutbuilder:1.6.0")
'com.facebook.fbui.textlayoutbuilder:textlayoutbuilder:aar:1.6.0'
<dependency org="com.facebook.fbui.textlayoutbuilder" name="textlayoutbuilder" rev="1.6.0">
  <artifact name="textlayoutbuilder" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.facebook.fbui.textlayoutbuilder', module='textlayoutbuilder', version='1.6.0')
)
libraryDependencies += "com.facebook.fbui.textlayoutbuilder" % "textlayoutbuilder" % "1.6.0"
[com.facebook.fbui.textlayoutbuilder/textlayoutbuilder "1.6.0"]

Dependencies

compile (1)

Group / Artifact Type Version
com.facebook.fbui.textlayoutbuilder : staticlayout-proxy jar 1.6.0

Project Modules

There are no modules declared in this project.

TextLayoutBuilder

Build text Layouts easily on Android.

Features

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

Download

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

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

or, if using Maven:

<dependency>
  <groupId>com.facebook.fbui.textlayoutbuilder</groupId>
  <artifactId>textlayoutbuilder</artifactId>
  <version>1.6.0</version>
  <type>aar</type>
</dependency>

Usage

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

    public CustomView(Context context) {
        super(context);
    }

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

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        // Draw the layout.
        layout.draw(canvas);
    }
}

Additional Usage

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

License

TextLayoutBuilder is Apache-2-licensed.

com.facebook.fbui.textlayoutbuilder

Facebook

We are working to build community through open source technology. NB: members must have two-factor auth.

Versions

Version
1.6.0
1.5.0
1.4.0
1.3.1
1.3.0
1.2.0
1.1.0
1.0.0