Example usage for android.text TextPaint setLetterSpacing

List of usage examples for android.text TextPaint setLetterSpacing

Introduction

In this page you can find the example usage for android.text TextPaint setLetterSpacing.

Prototype

public void setLetterSpacing(float letterSpacing) 

Source Link

Document

Set the paint's letter-spacing for text.

Usage

From source file:io.plaidapp.core.ui.transitions.ReflowText.java

private Layout createLayout(ReflowData data, Context context, boolean enforceMaxLines) {
    TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(data.textSize);// w  w w.  jav  a  2s.  co  m
    paint.setColor(data.textColor);
    paint.setLetterSpacing(data.letterSpacing);
    if (data.fontResId != 0) {
        try {
            Typeface font = ResourcesCompat.getFont(context, data.fontResId);
            if (font != null) {
                paint.setTypeface(font);
            }
        } catch (Resources.NotFoundException nfe) {
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        StaticLayout.Builder builder = StaticLayout.Builder
                .obtain(data.text, 0, data.text.length(), paint, data.textWidth)
                .setLineSpacing(data.lineSpacingAdd, data.lineSpacingMult).setBreakStrategy(data.breakStrategy);
        if (enforceMaxLines && data.maxLines != -1) {
            builder.setMaxLines(data.maxLines);
            builder.setEllipsize(TextUtils.TruncateAt.END);
        }
        return builder.build();
    } else {
        return new StaticLayout(data.text, paint, data.textWidth, Layout.Alignment.ALIGN_NORMAL,
                data.lineSpacingMult, data.lineSpacingAdd, true);
    }
}