How to Change Letter Spacing in a Textview

How to change letter spacing in a Textview?

check out android:textScaleX

Depending on how much spacing you need, this might help. That's the only thing remotely related to letter-spacing in the TextView.

Edit: please see @JerabekJakub's response below for an updated, better method to do this starting with api 21 (Lollipop)

Letter Spacing on EditText is not working

letterSpacing need to be a float value. Try android:letterSpacing="0.50"

Like @mike points out Android Studio does render letter spacing in preview since V4.0

Old Answer

Android Studio doesn't render the letter spacing in the preview, so you will have to manual run it on a device to view the changes.

Textview letter spacing issue

You're using wrap_content so the size is change according to the text. Simply use fixed dimension

<TextView
android:id="@+id/txt_letter"
android:layout_width="20dp" // fixed size
android:layout_height="20dp" // fixed size
android:background="@drawable/drawable_bg"
android:fontFamily="@font/viga"
android:padding="@dimen/padding_16dp"
android:text="A"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />

How to adjust text kerning in Android TextView?

AFAIK, you cannot adjust kerning in TextView. You may be able to adjust kerning if you draw the text on the Canvas yourself using the 2D graphics APIs.

Change text kerning or spacing in TextView?

The solution I found is to mix the solutions 1 and 2 that you described. Adding spaces between letters and than changing the TextScaleX only of the spaces, so you keep other characters the same. I built a custom class that extends TextView and allows you to define the letter spacing. Everything else is automatic =)

I posted the class on this other answer

Hope that helps ^^



Related Topics



Leave a reply



Submit