在做项目的时候动态设置TextView的左边或者右边图片的时候,图片不出现,最后发现是没有设置图片的边界属性,具体实现,如下:
Drawable drawable = getResources().getDrawable(id); drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); //设置边界 tvTitleMiddle.setCompoundDrawablePadding(5); tvTitleMiddle.setCompoundDrawables(null, null, drawable, null);
设置完成之后,textView右边的,向下箭头,就出来了,上面的id,是你要显示的图片的id,设置完成后的效果如下: