歇线

2016-03-03 42 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"/>