Skip to content Skip to sidebar Skip to footer

Justify Android Textview Library

I want to justify text in Android. But I don't want to use web view. I find Text Justify Android library on following link. But I can't use it. Please help me to use this library i

Solution 1:

What do you mean by "can't use it" ?? There is clear enough example how to use it.

In xml file

<com.bluejamesbond.text.DocumentView xmlns:ext="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    ext:documentView_antialias="true"
    ext:documentView_cacheConfig="auto_quality"
    ext:documentView_hyphen="-"
    ext:documentView_lineHeightMultiplier="2.0"
    ext:documentView_maxLines="100"
    ext:documentView_offsetX="10dp"
    ext:documentView_offsetY="10dp"
    ext:documentView_insetPadding="10dp"
    ext:documentView_insetPaddingBottom="10dp"
    ext:documentView_insetPaddingLeft="10dp"
    ext:documentView_insetPaddingRight="10dp"
    ext:documentView_insetPaddingTop="10dp"
    ext:documentView_progressBar="@id/progressBarXml"
    ext:documentView_reverse="false"
    ext:documentView_text="@string/xml_test_data"
    ext:documentView_textAlignment="justified"
    ext:documentView_textColor="@android:color/white"
    ext:documentView_textFormat="plain"
    ext:documentView_textSize="12sp"
    ext:documentView_textStyle="bold|strikeThru|underline"
    ext:documentView_textSubPixel="true"
    ext:documentView_textTypefacePath="fonts/helvetica.ttf"
    ext:documentView_wordSpacingMultiplier="5.0" />

and or if you want to create dynamically

DocumentViewdocumentView=newDocumentView(this, DocumentView.PLAIN_TEXT);  // Support plain text
documentView.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
documentView.setText("Insert your text here", true); // Set to `true` to enable justification

You can see details Github example page

Installation Procedure for Android Studio

[It is already their in their github repo, also mentioned by CommonsWare in the comment]

Just add to your app/build.gradle

dependencies {
    compile'com.github.bluejamesbond:textjustify-android:2.1.0'
} 

Solution 2:

I'm using this library:

Just add to your app/build.gradle

dependencies {
    compile'me.biubiubiu.justifytext:library:1.1'
} 

Then add put this into layout file:

<me.biubiubiu.justifytext.library.JustifyTextView
    android:id="@+id/texView"
    android:text="Paragraph1\nParagraph2\n"
    android:textSize="35sp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

Go to check screenshots and further detail.. https://github.com/ufo22940268/android-justifiedtextview

Solution 3:

JustifiedTextView is an Android View that justifies the Text! 🙌🏻

Android introduced in API level 26 the method setJustificationMode(int), which is meant to justify the text inside a TextView.

If your min API level is 26, I recommend TextView.setJustificationMode(int). But if you need to support older Android versions, JustifiedTextView is what you need 😉

Gradle:

implementation 'com.codesgood:justifiedtextview:1.1.0'

You just have to add the view in your layout:

<com.codesgood.views.JustifiedTextView
    android:id="@+id/tv_justified_paragraph"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:text="@string/lorem_ipsum_extended"
    android:textColor="@android:color/black"
    android:textSize="15sp" />

And that's it! 🎉 the text contained in the JustifiedTextView will be justified. (In this example I used 15sp as textSize, but you can use a different textSize and it won't be a problem).

You can set the text programmatically as well 👍🏻, you can even use JustifiedTextView as a regular TextView in your java class (because it extends TextView) and the result would be the same justified text in your UI.

Here is an example:

TextView justifiedParagraph = findViewById(R.id.tv_justified_paragraph); justifiedParagraph.setText(R.string.lorem_ipsum_extended);

Post a Comment for "Justify Android Textview Library"