Justify android TextView library

折月煮酒 提交于 2019-12-12 13:13:50

问题


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


回答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

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'
} 



回答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



来源:https://stackoverflow.com/questions/30083431/justify-android-textview-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!