android文字排列,Android TextView中有图片有文字混合排列
Android TextView中有图片有文字混合排列1.使用html.fromHtml2.新建ImageGetter3.使用标签demo:1.设置文字((TextView) findViewById(R.id.tv_gradlist_calorie_desc)).setText(Html.fromHtml(descString(), getImageGetterInstance(), null)
Android TextView中有图片有文字混合排列
1.使用html.fromHtml
2.新建ImageGetter
3.使用标签
demo:
1.设置文字
((TextView) findViewById(R.id.tv_gradlist_calorie_desc)).setText(Html
.fromHtml(descString(), getImageGetterInstance(), null));2.获取文字
/**
* 字符串
*
* @return
*/
private String descString() {
return "您消耗的总热量约等于4杯" + "" + "+5只" + "" + "+10个" + "" + "";
}3.imagegetter
/**
* ImageGetter用于text图文混排
*
* @return
*/
public ImageGetter getImageGetterInstance() {
ImageGetter imgGetter = new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
int fontH = (int) (getResources().getDimension(
R.dimen.textSizeMedium) * 1.5);
int id = Integer.parseInt(source);
Drawable d = getResources().getDrawable(id);
int height = fontH;
int width = (int) ((float) d.getIntrinsicWidth() / (float) d
.getIntrinsicHeight()) * fontH;
if (width == 0) {
width = d.getIntrinsicWidth();
}
d.setBounds(0, 0, width, height);
return d;
}
};
return imgGetter;
}效果
原文:http://blog.csdn.net/pangzaifei/article/details/38112053
更多推荐
所有评论(0)