目前我有一個像這樣的spannableString,圖標位於標題字符串的左側。問題是,有沒有辦法讓圖標在字符串上方,而圖標是對齊中心?如何將SpannableString修改爲字符串下方的圖標?
樣品是這樣的:
[] <==== This is the icon
TitleTest <=== This is the title
ABCD
感謝
這裏是我的代碼嘗試:
Drawable image = context.getResources().getDrawable(R.drawable.ic_launcher);
image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
// Replace blank spaces with image icon
SpannableString sb = new SpannableString(" " + tabTitles[position]);
ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BASELINE);
sb.setSpan(imageSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return sb;
感謝您的幫助