Text justification library in Java [duplicate]
Asked Answered
C

1

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.

Characterize answered 22/11, 2011 at 10:32 Comment(3)
Depeding on what kind of justification we're talking about - you can manage quite a lot by just using the android:gravity attribute.Reiser
Unfortunately I need full text justification with hyphening, if possible.Characterize
see also #1293075Mushy
C
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

Colene answered 18/3, 2012 at 1:14 Comment(3)
and the origWidth argument would be relative to? :)Bonniebonns
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 characterWidthnumberofcharacters=width. But for some unknown reason, that is NOT true. It is infact characterWidthnumberofcharacters+[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.Colene
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.Modiolus

© 2022 - 2024 — McMap. All rights reserved.