android - 证明 android TextView 库

标签 android textview justify

我想在 Android 中对齐文本。但我不想使用 WebView 。

我在以下链接中找到了 Text Justify Android 库。但是我不能使用它。

请帮助我在 Android Studio 中使用这个库。

Text Library

最佳答案

“不能使用”是什么意思??有足够清楚的示例说明如何使用它。

在xml文件中

<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" />

或者如果你想动态创建

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

可以看到详情Github example page

Android Studio 安装步骤

[它已经在他们的 github 仓库中,CommonsWare 在评论中也提到]

只需添加到您的 app/build.gradle

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

关于android - 证明 android TextView 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30083431/

相关文章:

android - 仪器化测试

android - 找不到默认 Activity ?

android - 如何清除堆栈中的当前 Activity ?

android - 如何避免android中相对布局中的重叠 View ?

java - 停止 TextView 上的 ClickableSpan 更改文本颜色

python - thinkpython2 右对齐第 70 列的含义

java - 算法与android应用程序之间的联系

android - TextView 中的 ImageSpan 对齐

html - Form Spacing justify-content-between 一个 <div> 到左边和一个 <span> 到右边

html - 对齐文本中的超链接间距