android 有类似 css 的属性“word-wrap”吗?
我只是希望我的文本不被空格、破折号等包裹,如下所示:
- hello, w
- orld
代替
- hello,
- world
不幸的是,android没有这个属性。但您可以使用 ReplacementTransformationMethod 替换所有中断字符。
class WordBreakTransformationMethod extends ReplacementTransformationMethod
{
private static WordBreakTransformationMethod instance;
private WordBreakTransformationMethod() {}
public static WordBreakTransformationMethod getInstance()
{
if (instance == null)
{
instance = new WordBreakTransformationMethod();
}
return instance;
}
private static char[] dash = new char[] {'-', '\u2011'};
private static char[] space = new char[] {' ', '\u00A0'};
private static char[] original = new char[] {dash[0], space[0]};
private static char[] replacement = new char[] {dash[1], space[1]};
@Override
protected char[] getOriginal()
{
return original;
}
@Override
protected char[] getReplacement()
{
return replacement;
}
}
'\u2011' 是不间断破折号,'\u00A0' 是不间断空格。不幸的是,UTF 没有不间断的斜杠('/')模拟,但您可以使用除法斜杠('∕')。
要使用此代码,请将 WordBreakTransformationMethod 的实例设置为您的 EditText。
myEditText.setTransformationMethod(WordBreakTransformationMethod.getInstance());
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)