9
8

More than 5 years have passed since last update.

Android8.0でTextViewに表示した文字列の折り返し位置がおかしい

Posted at

TextViewに文字列を設定したので表示を確認

Android 8.0のEmulator Android 8.1のEmulator

うん!文字の折り返し位置がおかしいね!!

ちなみにコードがこちら!(ただtextに文字列を設定しているだけ)

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="さすがディオ!俺達に出来ないことを平然とやってのけるッ!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

と言うわけで調べてみた

google issue trackerにこんな内容があった
https://issuetracker.google.com/issues/64418117

どうやら「breakStrategy = "simple"」を設定すれば正しく表示される様子

実際に試してみた結果

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="さすがディオ!俺達に出来ないことを平然とやってのけるッ!"
    android:breakStrategy = "simple"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
Android 8.0のEmulator Android 8.1のEmulator

「breakStrategy = "simple"」を設定すると同じところで折り返してくれていることを確認

breakStrategyってなんぞ?

Android公式ではここの項目
https://developer.android.com/reference/android/widget/TextView#attr_android:breakStrategy

「breakStrategy = "high_quality"」を設定すると本投稿の内容である折り返し位置がおかしい状態で表示されてしまうため
defaultでは「breakStrategy = "high_quality"」が設定されている様子だが
Android8.0ではこの問題は修正されていないようなのでAndroid8.0のみこの表示状態となってしまう

ちなみに…

「breakStrategy = "balanced"」を設定すると下図のように表示されたため端で折り返すためには
「breakStrategy = "simple"」と設定するしかない様子

Android 8.0のEmulator Android 8.1のEmulator
9
8
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
9
8