给TextView设置compoundDrawable要注意的问题

如果textView已经有compoundDrawable的话,要注意新图片的范围,否则会出现图片和文字位置偏差的情况。这种情况下,可以先获取旧图片的范围。

                    Drawable[] compoundDrawables = img.getCompoundDrawables();
                    Rect bounds = compoundDrawables[1].getBounds();
                    bd.setBounds(bounds);
                    img.setCompoundDrawables(null, bd, null, null);


一边情况下,用setCompoundDrawablesWithIntrinsicBounds就可以了

猜你喜欢

转载自ccsosnfs.iteye.com/blog/1935243