歇線

2016-03-03 25 views
2

如何突破線路在機器人EditText字母,所以它成了這個樣子:歇線

Hello how to br 
eak by letters 
instead of word 
s 

取而代之的是:

Hello how to 
break by 
letters 
instead of 
words 

CSS中的模擬是word-break: break-all

PS當然,文本正在動態變化。

回答

0

試試這個 // tmpString - 要顯示的字串

// 15 - 沒有。信你要改變按照您的要求

int index = 0; 
StringBuffer finalString = new StringBuffer(); 
while (index < tmpString.length()) { 
    finalString.append(tmpString.substring(index, Math.min(index + 15,tmpString.length()))+"\n"); 
    index += 15; 
} 
editText.setText(finalString); 
0

它所稱的「對齊文本」或「文本對齊」,但在Android它不支持,至少到現在爲止。

有一種解決方案,如果你想實施。它使用WebView並加載HTML格式的文本並將body樣式設置爲justify。如果你真的需要'文本理由',這只是一個解決方案。

0

您可以使用自動調整編輯文本具有以下屬性:

android:inputType="textMultiLine" 
android:layout_height="wrap_content" 

完整的EditText佈局實例:

<EditText 
    android:layout_width="match_parent" 
    android:inputType="textMultiLine" 
    android:layout_height="wrap_content" 
    android:hint="Enter Text" 
    android:textColorHint="@color/primary_color" 
    android:ems="10" 
    android:imeOptions="actionDone" 
    android:id="@+id/message_input" 
    android:layout_gravity="center_horizontal"/>