TextLayoutBuilder uses a builder pattern to configure the properties
required to create a Layout. The methods on this builder class are
similar to TextView's. On calling build(), the
TextLayoutBuilder creates a text Layout based on
the properties set on it.
Layout layout = new TextLayoutBuilder()
.setText("TextLayoutBuilder makes life easy")
.setWidth(400 /*, MEASURE_MODE_EXACTLY */)
.build();
TextLayoutBuilder uses a builder pattern to configure the properties
for the Layout. Gone are those days of trying to set properties on
a StaticLayout.
Same properties will return same Layout on subsequent build()
calls. This reduces allocation on commonly used texts.
On 4.0+ devices, TextLayoutBuilder can warm up the FreeType font cache. By drawing these
glyphs on a background thread onto a Picture, TextLayoutBuilder warms
these glyphs and can help reduce their render time.
build.gradle:
compile 'com.facebook.fbui.textlayoutbuilder:textlayoutbuilder:1.7.0'
<dependency>
<groupId>com.facebook.fbui.textlayoutbuilder</groupId>
<artifactId>textlayoutbuilder</artifactId>
<version>1.7.0</version>
<typen>aar</type>
</dependency>
TextLayoutBuilder:
TextLayoutBuilder builder = new TextLayoutBuilder()
.setText("TextLayoutBuilder makes life easy")
.setWidth(400);
build() on the builder to get a Layout:
Layout layout = builder.build();
Layout in your code:
layout.draw(canvas);
TextLayoutBuilder.
mTextLayoutBuilder.setShouldCacheLayout(true);
GlyphWarmer for the TextLayoutBuilder.
mTextLayoutBuilder
.setShouldWarmText(true)
.setGlyphWarmer(new GlyphWarmerImpl());
TextLayoutBuilder object.
ResourceTextLayoutHelper.updateFromStyleResource(
mTextLayoutBuilder,
mContext,
resId);