Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 in Android Studio.

Text Library

like image 768
amir Avatar asked Sep 25 '26 02:09

amir


1 Answers

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

DocumentView documentView = new DocumentView(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'
} 
like image 59
Amit K. Saha Avatar answered Sep 27 '26 16:09

Amit K. Saha