Reputation: 32243
I'm trying to put inline images in a TextView. Here goes my code:
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);
It works (see the image below) but I would need the image to be vertically centered. How can I do that?
Thanks
Upvotes: 0
Views: 278
Reputation: 157457
Instead of use HTML, you can use
labelVotes.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, R.drawable.icon_upvotes);
and playing a little bit with padding, using setCompoundDrawablePadding
Upvotes: 4