I need to justify some text (RTL), which is a string (S1
) from the server. But a TextView
can't justify text, so I have to use a WebView
, now I have to create a HTML file in which
will display S1
. And then I store the address of that html file in the database and then I display that html file. I've seen this question asked before on SO and many have recommended to use a 3rd party library, I've tried all of those approaches to no avail (they work in 90% of scenarios but are no fully reliable).
I feel that this approach seems convoluted, I was wondering if there is a better approach?
Try this:
Add a TextViewJustify.java file in src folder.
TextViewJustify.java wil be like this
And use this class like this:
In my case it was 225f. change it according to your need.
i made simple class.
this can be used just like TextView
You can justify Text using WebView Simply
Use web view
I use the following code that answer with very people that need this subject and i create formula that support in every display.
and for calling this you mus use following code, I tested for Persian language and in every display and device worked fine.
this algorithm tested on various device and worked fine in normal activity (not dialog) and
wrap-content
width forTextView
, and worked with every padding and margin.if not good for you, you can changewidthJustify
until look good to you, I hope this useful. for newly update see ThisLIBRARY: https://github.com/bluejamesbond/TextJustify-Android
SUPPORTS: Android 2.0 to 5.X; String/Spannables; RTL language support! NO WEBVIEW :)
SCREENSHOT