TextLayoutBuilder builder = new TextLayoutBuilder()
.setText("TextLayoutBuilder makes life easy")
.setTextColor(Color.BLUE)
.setWidth(400 /*, MEASURE_MODE_EXACTLY */);
Call build() on the builder to get a Layout:
Layout layout = builder.build();
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
Cache the layouts for commonly used strings by turning on caching in the TextLayoutBuilder.
textLayoutBuilder.setShouldCacheLayout(true);
Glyph warming provides significant performance boost for large blurbs of text.
Turn this on and pass in a GlyphWarmer for the TextLayoutBuilder.
TextLayoutBuilder
Build text Layouts easily on Android.
Features
Layouts easily.Layouts.Layouts of commonly used strings.Download
If using Gradle, add this to your
build.gradle:or, if using Maven:
Usage
Set the properties on the
TextLayoutBuilder:Call
build()on the builder to get aLayout:Use the
Layoutin your code:Additional Usage
Cache the layouts for commonly used strings by turning on caching in the
TextLayoutBuilder.Glyph warming provides significant performance boost for large blurbs of text. Turn this on and pass in a
GlyphWarmerfor theTextLayoutBuilder.Import a style defined in XML into a
TextLayoutBuilderobject.License
TextLayoutBuilder is Apache-2-licensed.