Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/facebook/TextLayoutBuilder
An Android library that allows you to build text layouts more easily.
https://github.com/facebook/TextLayoutBuilder
Last synced: about 1 month ago
JSON representation
An Android library that allows you to build text layouts more easily.
- Host: GitHub
- URL: https://github.com/facebook/TextLayoutBuilder
- Owner: facebook
- License: apache-2.0
- Created: 2016-11-01T22:04:45.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2024-10-08T14:30:57.000Z (2 months ago)
- Last Synced: 2024-10-29T15:17:08.945Z (about 1 month ago)
- Language: Java
- Homepage: https://facebook.github.io/TextLayoutBuilder
- Size: 494 KB
- Stars: 1,475
- Watchers: 48
- Forks: 133
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-github-android-ui - TextLayoutBuilder - Facebook出品的在Android中轻松实现文字布局 (TextView)
README
# TextLayoutBuilder
Build text [Layout](https://developer.android.com/reference/android/text/Layout.html)s easily on Android.
## Features
- Create text `Layout`s easily.
- Reuse builders to create similarly styled `Layout`s.
- Cache `Layout`s of commonly used strings.
- Improve performance by warming up the FreeType cache.## Download
If using Gradle, add this to your `build.gradle`:```groovy
compile 'com.facebook.fbui.textlayoutbuilder:textlayoutbuilder:1.7.0'
```or, if using Maven:
```xml
com.facebook.fbui.textlayoutbuilder
textlayoutbuilder
1.7.0
aar```
## Usage
1. Set the properties on the `TextLayoutBuilder`:
```java
TextLayoutBuilder builder = new TextLayoutBuilder()
.setText("TextLayoutBuilder makes life easy")
.setTextColor(Color.BLUE)
.setWidth(400 /*, MEASURE_MODE_EXACTLY */);
```2. Call `build()` on the builder to get a `Layout`:
```java
Layout layout = builder.build();
```3. Use the `Layout` in your code:
```java
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`.
```java
textLayoutBuilder.setShouldCacheLayout(true);
```2. Glyph warming provides significant performance boost for large blurbs of text.
Turn this on and pass in a `GlyphWarmer` for the `TextLayoutBuilder`.
```java
textLayoutBuilder
.setShouldWarmText(true)
.setGlyphWarmer(new GlyphWarmerImpl());
```3. Import a style defined in XML into a `TextLayoutBuilder` object.
```java
ResourceTextLayoutHelper.updateFromStyleResource(
textLayoutBuilder, // builder object
context, // Activity context
resId); // style resource id
```## License
TextLayoutBuilder is Apache-2-licensed.