9

Possible Duplicate:
Can i set property of Textview like justify?

I'm writing an android app which needs text justification, which isn't supported natively, and I don't think using a WebView is going to work because of font and text sizes in relation to screen resolution and dimensions. With this in mind I'm going to write a custom view which extends the TextView which will do text justification and was wondering if anybody knows of any code I can look at which does this already to save me some time. Any other helpful advice would be greatly appreciated too.

Community
  • 1
  • 1
Martyn
  • 16,432
  • 24
  • 71
  • 104

1 Answers1

33

UPDATED

We have created a simple class for this. There are currently two methods to achieve what you are looking for. Both require NO WEBVIEW and SUPPORTS SPANNABLES.

LIBRARY: https://github.com/bluejamesbond/TextJustify-Android

SUPPORTS: Android 2.X to 5.X

SETUP

// Please visit Github for latest setup instructions.

SCREENSHOT

Comparison.png

Community
  • 1
  • 1
Mathew Kurian
  • 5,949
  • 5
  • 46
  • 73
  • and the origWidth argument would be relative to? :) – mahkie Sep 12 '12 at 10:38
  • Good question. Well its been a while since I looked at it. Let me see what I can explain to you though. So when I initally wrote this, I thought that the characterWidth*numberofcharacters=width. But for some unknown reason, that is NOT true. It is infact characterWidth*numberofcharacters+[X]=width in which I don't know what [X] is. But I know that there is no direct correlation between [X] and the width. I will leave it to you to get this answer :D Please edit my response if you find out. – Mathew Kurian Sep 23 '12 at 18:41
  • The reason is because the characters have varying width. For example, with some fonts the ! symbol is slimmer than the @ symbol. If you want to have characterWidth*numberofcharacters=width, then you'd need a fixed-width font. If you're not convinced, look at a fixed-width font. You'll see that the ! character has space to the left and right of it, while the @ symbol does not. – Steven Linn Nov 21 '13 at 14:55