Android 超级和下标范围工作不正常
我在使用Android 超级和下标范围工作不正常,android,android-4.4-kitkat,subscript,superscript,Android,Android 4.4 Kitkat,Subscript,Superscript,我在使用KitKat时遇到了子字符和上标字符的问题,所以我想做一个方法,给出一个文本,返回超级和子脚本的位置,这样我就可以使用SuperScriptSpan和SubScriptSpan,因为我不想使用Html.fromHtml功能。 我的正则表达式分别用于检测子脚本和超级脚本: [\u2080-\u2089]和[\u2070-\u2079] 由于文本设置不正确,所以除了渲染实际发生时,其他一切似乎都正常工作。在下一个屏幕截图中,您可以看到跨度的变化: 获取位置的代码如下所示: public s
KitKat
时遇到了子字符和上标字符的问题,所以我想做一个方法,给出一个文本,返回超级和子脚本的位置,这样我就可以使用SuperScriptSpan
和SubScriptSpan
,因为我不想使用Html.fromHtml
功能。我的正则表达式分别用于检测子脚本和超级脚本:
[\u2080-\u2089]
和[\u2070-\u2079]
由于文本设置不正确,所以除了渲染实际发生时,其他一切似乎都正常工作。在下一个屏幕截图中,您可以看到跨度的变化:
获取位置的代码如下所示:
public static ArrayList<int[]> getSuperScripts(String body) {
ArrayList<int[]> spans = new ArrayList<>();
Pattern pattern = Pattern.compile("[\\u2070-\\u2079]");
Matcher matcher = pattern.matcher(body);
// Check all occurrences
while (matcher.find()) {
int[] currentSpan = new int[2];
currentSpan[0] = matcher.start();
currentSpan[1] = matcher.end();
spans.add(currentSpan);
}
return spans;
}
publicstaticarraylistgetsuperscripts(字符串体){
ArrayList span=新的ArrayList();
Pattern=Pattern.compile(“[\\u2070-\\u2079]”);
匹配器匹配器=模式匹配器(主体);
//检查所有事件
while(matcher.find()){
int[]currentSpan=新的int[2];
currentSpan[0]=matcher.start();
currentSpan[1]=matcher.end();
span.add(当前span);
}
返回跨度;
}
如果用于下标,则正则表达式会发生变化。下面是我设置所有跨度的代码:
for (int i = 0; i < superScriptSpan.size(); i++) {
int[] span = superScriptSpan.get(i);
int superStart = span[0];
int superEnd = span[1];
commentsContent.setSpan(new SuperscriptSpan(),
superStart,
superEnd, 0);
}
for(int i=0;i
同样,从超级变为下标。提前谢谢