0
            SpannableStringBuilder authorText = new SpannableStringBuilder("");
            ImageSpan is = new ImageSpan(getActivity(), R.drawable.ic_birdhead);
            for (Author a : mStory.authors) {
                if (!TextUtils.isEmpty(a.authorName)) {

                String prefix = "";
                if (count == 0) {
                    prefix = "By: ";
                } else if (count > 0 && count < mStory.authors.size()-1) {
                    prefix = ", ";
                } else {
                    prefix = " and ";
                }

                authorText.append(prefix + a.authorName + " ");
                authorText.setSpan(is, authorText.length()-1, authorText.length(), 0);
                //authorText.setSpan(is, authorText.length()-2, authorText.length()-1, 0);
                              //^ I put a second one there just to check is two will populate
                count++;
            }

所以.. 无论如何它都会经历一个 for 循环,但我放了 2 个 setSpan() 来查看最后一次迭代是否会填充 2 个图像。它只在字符串的最后填充一个图像。也许我必须输入某个标志才能使设置跨度产生多个?

4

1 回答 1

0

尝试这个:

SpannableStringBuilder authorText = new SpannableStringBuilder("");
            ImageSpan is = new ImageSpan(getActivity(), R.drawable.ic_birdhead);
            for (Author a : mStory.authors) {
                if (!TextUtils.isEmpty(a.authorName)) {

                String prefix = "";
                if (count == 0) {
                    prefix = "By: ";
                } else if (count > 0 && count < mStory.authors.size()-1) {
                    prefix = ", ";
                } else {
                    prefix = " and ";
                }

                authorText.append(prefix + a.authorName + " ");
                authorText.setSpan(is, authorText.length()-1, authorText.length(), 0);

                is = new ImageSpan(getActivity(), R.drawable.ic_birdhead);

                authorText.setSpan(is, authorText.length()-2, authorText.length()-1, 0);
                              //^ I put a second one there just to check is two will populate
                count++;
            }
于 2013-08-13T21:21:53.903 回答