7
3

More than 3 years have passed since last update.

AndroidのTextViewで文字幅を調整する

Last updated at Posted at 2020-02-01

はじめに

行間の記事は多数あれど、文字幅で調べると全然なくて苦戦したので記事にしておきます。

やり方

とても簡単。letterSpacing属性をつけるだけ。APIレベルは21以上です。

activity_main.xml

...

   <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:textSize="20dp"
        android:letterSpacing="1.1"
        />

...



文字幅が広がりました!
スクリーンショット 2020-02-01 17.05.47.png

単位はemでデフォルト値は0.0。逆に文字幅を狭める場合はマイナスを設定してあげます。

スクリーンショット 2020-02-01 17.30.52.png

letterSpacing="-0.2"を設定した状態

おわりに

とっても簡単なんだけど意外と情報がない。。需要ないのだろうか?

7
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
3