How do you get textview to be justified ? is it possible to get the solution? I have searched most of the forums but i didn't make it up. please help me out.
Asked
Active
Viewed 4.1k times
8
-
Here is an idea that should do the trick http://stackoverflow.com/questions/8225353/text-justification-library-in-java/9755219#9755219 – Mathew Kurian Mar 18 '12 at 04:47
3 Answers
15
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.0 to 5.X
SETUP
// Please visit Github for latest setup instructions.
SCREENSHOT

Community
- 1
- 1

Mathew Kurian
- 5,949
- 5
- 46
- 73
-
2
-
1@fargath: did u try this? ((TextView)findViewById(R.id.textview)).setText(input); TextViewJustify.justifyText(((TextView)findViewById(R.id.textview)), 305f); //Start from a small number like 150f and move up from there to get the exact width. //I haven't fixed this problem yet. 305f works best for me in this case. – Mathew Kurian Apr 25 '12 at 04:02
-
1
-
@Xylian Please open an issue in my github respository for this and then we can follow up there – Mathew Kurian Oct 14 '13 at 08:30
-
@mk1 i posted an issue on the repo, when you put the TextViewEx inside a ScrollView, it cuts some of the text at the bottom, its like the scrollview cant calculate the height properly – RonEskinder May 03 '14 at 23:17
-
12
Android doesn't support text justification, sorry. You can use android:gravity
attribute to align text to left or right or center etc, but you can't really justify it. The only option I guess is to use a WebView
to show text and then use CSS to get the text justified.

Konstantin Burov
- 68,980
- 16
- 115
- 93
-
Unfortunately, CSS text justification remains difficult too. Improving with latest specs, but there are still major issues such as Webkit not breaking long URLs. – mahemoff Dec 29 '12 at 14:10
1
<RelativeLayout android:id="@+id/RelativeLayout01"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<TextView android:id="@+id/TextView2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="I'm TextView- Left" android:layout_alignParentLeft="true">
</TextView>
<TextView android:id="@+id/TextView1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="I'm TextView- Right" android:layout_alignParentRight="true">
</TextView>
</RelativeLayout>
ScreenShot:
Hope this helps. If you have any difficulties write back.- Thanks

Piyush Patel
- 1,765
- 1
- 16
- 29
-
This works well so long as you don't have too many columns to handle. – Andi Jay Jun 08 '12 at 02:26
-
This is not text justification, only a work-around when you have multiple columns. How about one column, though? – vandus Jul 02 '14 at 14:57
-
What do you want to explain here. Please tell any solution for text justification in android without using webView. – Prateek Sharma Nov 24 '17 at 12:20