这是我在文本上添加图片的代码,但有一个很大的 图片之间的空间。我怎样才能删除空间并让它 图片是彼此相邻的,而不是弄乱它最初做的事情。 你能告诉我应该修改我的代码吗?
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
}