如果textView已经有compoundDrawable的话,要注意新图片的范围,否则会出现图片和文字位置偏差的情况。这种情况下,可以先获取旧图片的范围。
一边情况下,用setCompoundDrawablesWithIntrinsicBounds就可以了
Drawable[] compoundDrawables = img.getCompoundDrawables();
Rect bounds = compoundDrawables[1].getBounds();
bd.setBounds(bounds);
img.setCompoundDrawables(null, bd, null, null);
一边情况下,用setCompoundDrawablesWithIntrinsicBounds就可以了