2013-03-25 29 views
3

我的問題與描述的here非常相似。但只有在Android 4.2設備上測試時纔會出現。在使用Android 2.2的舊版測試設備上,一切都很順利。ImageSpan在Android 4.2中移除以下文本Jelly Bean

我的問題

我在一個TextView其外殼更換TextView中的一個字符的中間增加一個ImageSpan。在Android 4.2 將不會顯示ImageSpan後的文字。在Android 2.2上,一切都如預期般運作。

代碼示例

CharSequence chars = txtView.getText(); 
    SpannableStringBuilder stringBuilder = new SpannableStringBuilder(chars); 

    for (int i = 0; i < chars.length(); i++) { 
     int codePoint = Character.codePointAt(chars, i); 
     if (codePoint > 255) { 
       // loading the bitmap ... 
       ImageSpan img = new ImageSpan(context, bmp, ImageSpan.ALIGN_BASELINE); 
       stringBuilder.replace(i, i + 1, ""); 
       stringBuilder.setSpan(img, i, i + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 
     } 
    } 
    txtView.setText(stringBuilder, BufferType.SPANNABLE); 

截圖

Android 2.2 Screenshot which shows how it should be Android 4.2 Screen which shows the bug

我到目前爲止已經試過

我幾乎試過任何Spanned - 你可以在setSpan上添加,但在4.2設備上沒有任何作用。

回答

3

我真的很抱歉,我發佈了這個,因爲我自己找到了答案。 我真的認爲我以前試過Spanned.SPAN_INCLUSIVE_EXCLUSIVE,但我顯然沒有。反正...

stringBuilder.setSpan(img, i, i + 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

對我的作品在Android 4.2及Android 2.2的。希望這個線程能夠幫助未來的其他人。

相關問題