AlignTextView:字體對齊的textview
字體對齊的textview。分為支持選擇復制的CBAlignTextView 和不支持選擇復制的AlignTextView。比github上已經存在的JustifyTextView效果要好,不會出現字符間隔很大的情況。

使用說明:
系統要求
Android 4.0以上
快速使用
build.gradle加入dependencies
compile 'me.codeboy.android:align-text-view:2.3.0'
AlignTextView (不支持選擇復制,在不需要進行選擇復制的情況下使用,排版效果好)
<me.codeboy.android.aligntextview.AlignTextView android:id="@+id/alignTv" android:layout_width="match_parent" android:layout_height="wrap_content"/>
CBAlignTextView (新的版本,支持選擇復制,排版效果比較的好)
<me.codeboy.android.aligntextview.CBAlignTextView android:id="@+id/cbAlignTv" android:textIsSelectable="true" android:layout_width="match_parent" android:layout_height="wrap_content"/>
如果需要支持android默認的選擇復制,請在xml中加入以下代碼:
android:textIsSelectable="true"
相關方法
1.CBAlignTextView
CBAlignTextView中增加了以下方法獲取TextView的文本內容,請不要使用getText()獲取
getRealText()
由于Android L(5.0)之后對中文的版本進行了變化,造成不能由中文標點作為行首,所以為了能夠使CBAlignTextView看起來更加工整,建議將中文符號用英文符號替換(默認不轉換),可以通過以下三種方式轉化
使用轉化函數轉化標點符號:
CBAlignTextViewUtil.replacePunctuation(String text)
在設置CBAlignTextView文本前(setText),調用以下方法:
setPunctuationConvert(boolean convert)
可以直接在xml布局中進行設置
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cb="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <me.codeboy.android.aligntextview.CBAlignTextView android:id="@+id/cbAlignTextView" android:layout_width="match_parent" android:layout_height="wrap_content" cb:punctuationConvert="true" android:textIsSelectable="true" android:textSize="14dsp"/> </LinearLayout>
2.AlignTextView
AlignTextView是舊的版本,不支持選擇復制,但是可以自定義最后一行的對齊方式
setAlign(Align align)
設置每一段最后一行對齊方式,默認居左對齊 ,同時也可以在xml注釋中設置對其方式:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cb="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <me.codeboy.android.aligntextview.AlignTextView android:id="@+id/alignTextView" android:layout_width="match_parent" android:layout_height="wrap_content" cb:align="center" android:textSize="14dsp"/> </LinearLayout>
使用說明
不用進行選擇復制的時候使用 AlignTextView,需要進行選擇復制的時候使用CBAlignTextView。
AlignTextView與CBAlignTextView在對齊的時候不會對英文單詞等進行考慮,它們都是以字符(character)為基礎的,不是詞(word)。
使用CBAlignTextView時建議進行中文標點的轉換。
demo項目位與app下,可以單獨提取出me.codeboy.android.aligntextview.AlignTextView和me.codeboy.android.aligntextview.CBAlignTextView使用。
Status API Training Shop Blog About Pricing