こんにちは皆さん、テキストビューに少し問題があります。スパン可能な文字列を使用しており、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);
}
あなたが解決策を知っているなら、私にそれを解決するのを手伝ってください、私はすべての重力を試しましたが、画像が中央にあるのに残りのテキストが下にある理由はあまりにも奇妙です!