0
我想在TextView中顯示圖像作爲笑臉。我有一個獲取字符串的方法,並將ImageSpans添加到CharSequence中,該CharSequence用圖形版本替換文本表情圖標,如:-)。 不要在Android中使用ImageSpan在TextView中顯示圖像
public Spannable addSmileySpans(CharSequence text) {
SpannableStringBuilder builder = new SpannableStringBuilder(text);
Matcher matcher = mPattern.matcher(text);
while (matcher.find()) {
int resId = mSmileyToRes.get(matcher.group());
builder.setSpan(new ImageSpan(mContext, resId),
matcher.start(), matcher.end(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return builder;
}
然後我用它在我的適配器上:
viewHolder.txtReceivedBody.setText(parser.addSmileySpans(message.body));
而且,這裏定義的TextView elemnt:
<TextView
android:id="@+id/txtReceivedBody"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/imgReceivedDirection"
android:layout_marginRight="30dp"
android:background="@drawable/selector_conversation_received"
android:minHeight="40dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:textSize="18sp"
android:autoLink="all"
android:gravity="right"/>
遺憾的是,並沒有表現出的TextView和只顯示圖像一個主要字符串。我應該怎麼做才能解決它?
請烏拉圭回合後所需的圖像請.. – 2014-12-06 07:00:19
我只是想表明一個笑臉圖像。我在上面添加了它。 – 2014-12-06 07:06:24