0

How do I JUSTIFY align text in a static layout programmatically? Thanks for your time.

I only see the following options for staticLayout.setAlignment():

Layout.Alignment.ALIGN_CENTER
Layout.Alignment.ALIGN_NORMAL
Layout.Alignment.ALIGN_OPPOSITE

enter image description here

  • Your question is not clear, what do you actually want to do with the `TextView` alignment? – MojoJojo Oct 27 '22 at 11:57
  • @MojoJojo I added an illustration. I want the second effect. JUSTIFIED –  Oct 27 '22 at 12:02
  • Did you try [setJustificationMode](https://developer.android.com/reference/android/widget/TextView#setJustificationMode(int)) ? – Nitish Oct 27 '22 at 12:16

1 Answers1

0

You can set it like textView.justificationMode = JUSTIFICATION_MODE_INTER_WORD. But it requires Android O (Api level 26).

source: https://stackoverflow.com/a/42991773/19115089

Another option would be to try a third party library like https://github.com/mathew-kurian/TextJustify-Android (but no longer maintained)

Lucas.K
  • 574
  • 3
  • 12