8

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.

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
fargath
  • 7,844
  • 6
  • 24
  • 36
  • 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 Answers3

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

Comparison.png

Community
  • 1
  • 1
Mathew Kurian
  • 5,949
  • 5
  • 46
  • 73
  • 2
    I used this library but it doesn't work for me. – fargath Apr 24 '12 at 09:54
  • 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
    library doesn't work properly – Jacek Kwiecień Oct 14 '13 at 08:15
  • @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
  • @RonEskinder These issues have been fixed. – Mathew Kurian Jan 15 '15 at 23:08
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:

alt text

Hope this helps. If you have any difficulties write back.- Thanks

Piyush Patel
  • 1,765
  • 1
  • 16
  • 29