[英]Inline images in a TextView
我正在嘗試將內聯圖像放入 TextView 中。 這是我的代碼:
ImageGetter imageGetter = new ImageGetter() {
public Drawable getDrawable(String source) {
Drawable d = ctx.getResources().getDrawable(Integer.parseInt(source));
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}
};
CharSequence votesString="124 votes";
votesString=Html.fromHtml(votesString
+"(<img src='" + R.drawable.icon_upvotes + "'/>)", imageGetter, null);
labelVotes.setText(votesString);
它可以工作(見下圖),但我需要圖像垂直居中。 我怎樣才能做到這一點?
謝謝
而不是使用 HTML,您可以使用
labelVotes.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, R.drawable.icon_upvotes);
並使用setCompoundDrawablePadding
玩一點填充
為什么不使用android:drawableRight ?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.