大家好,我的 textview 有一点问题,我在上面使用了 Spannable String,完全位于 TextView 的中间,但其余的文本似乎在 TextView 的底线,所以如果我们说 |-| 是图像跨度, _是文本的其余部分,它是这样的:
|-| ____
我需要的是这样的东西:
|-|--
这是我的代码:
holder.theMessage.setText(getSmiledText(mContext,mCursor.getString(mCursor.getColumnIndex("message")),holder.theMessage),TextView.BufferType.SPANNABLE);
// holder.theMessage.setText(mCursor.getString(mCursor.getColumnIndex("message")));
if(isright==0){
holder.theMessage.setBackgroundResource(R.drawable.bubble_yellow);
}else{
holder.theMessage.setBackgroundResource(R.drawable.bubble_green);
}
holder.theMessage.setGravity(Gravity.CENTER_VERTICAL);
public static Spannable getSmiledText(Context context, CharSequence text,TextView tv) {
Spannable spannable = spannableFactory.newSpannable(text);
addSmiles(context, spannable,tv);
return spannable;
}
public static boolean addSmiles(Context context, Spannable spannable,final TextView tv) {
boolean hasChanges = false;
for (Entry<Pattern,String> entry : emoticons.entrySet()) {
Matcher matcher = entry.getKey().matcher(spannable);
while (matcher.find()) {
boolean set = true;
for (ImageSpan span : spannable.getSpans(matcher.start(),
matcher.end(), ImageSpan.class))
if (spannable.getSpanStart(span) >= matcher.start()
&& spannable.getSpanEnd(span) <= matcher.end())
spannable.removeSpan(span);
else {
set = false;
break;
}
if (set) {
if(sources.get(entry.getValue()).equals("internal")){
Drawable mDrawable = null;
try {
mDrawable = new BitmapDrawable(context.getResources(),context.getResources().getAssets().open(entry.getValue()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(types.get(entry.getValue()) == true){
mDrawable.setBounds(0, 0, getDimensions.MAIN_BUTTON_TEXT_SIZE*4, getDimensions.MAIN_BUTTON_TEXT_SIZE*4);
}else{
int width = mDrawable.getIntrinsicWidth();
int height = mDrawable.getIntrinsicHeight();
mDrawable.setBounds(0, 0, width > 0 ? width : 0, height > 0 ? height : 0);
}
hasChanges = true;
spannable.setSpan(new ImageSpan(mDrawable,ImageSpan.ALIGN_BASELINE),matcher.start(), matcher.end(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
如果您知道解决方案,请帮我解决它,我已经尝试了所有重力但它太奇怪了为什么图像在中间而其余的文本在底部!