我正在尝试将内联图像放入 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);
它可以工作(见下图),但我需要图像垂直居中。我怎样才能做到这一点?
谢谢
最佳答案
您可以使用
而不是使用 HTMLlabelVotes.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, R.drawable.icon_upvotes);
并使用 setCompoundDrawablePadding
进行一点填充
关于java - TextView 中的内嵌图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21848957/