这是我在文字上添加图片的代码,但是图片之间有很大的空间。如何删除空间并让图片彼此相邻而不会弄乱它最初的功能。你能告诉我我应该修改我的代码吗?
te2.setText(" ");
String t = te1.getText().toString();
final SpannableStringBuilder builder1 = new SpannableStringBuilder(
te1.getText());
char[] aa = t.toString().toCharArray();
for (int i = 0; i < aa.length; i++) {
switch (aa[i]) {
case 's':
while (builder1.toString().indexOf("s") > -1) {
ImageSpan imageSpan = new ImageSpan(
getBaseContext(), R.drawable.a1);
int pos = builder1.toString().indexOf("s");
builder1.replace(pos, pos + 1, "$");
builder1.setSpan(imageSpan, pos, pos + 1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
te2.setText(builder1);
break;
case 'g':
while (builder1.toString().indexOf("g") > -1) {
ImageSpan imageSpan = new ImageSpan(
getBaseContext(), R.drawable.a2);
int pos = builder1.toString().indexOf("g");
builder1.replace(pos, pos + 1, "$");
builder1.setSpan(imageSpan, pos, pos + 1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
te2.setText(builder1);
break;
case 'v':
while (builder1.toString().indexOf("v") > -1) {
ImageSpan imageSpan = new ImageSpan(
getBaseContext(), R.drawable.a2);
int pos = builder1.toString().indexOf("v");
builder1.replace(pos, pos + 1, "$");
builder1.setSpan(imageSpan, pos, pos + 1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
te2.setText(builder1);
break;
} // / end of loop
} // end of switch
}