美文网首页
给TextView设置compoundDrawable要注意的问

给TextView设置compoundDrawable要注意的问

作者: ccsosnfs | 来源:发表于2019-03-14 16:53 被阅读0次

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

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

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

相关文章

网友评论

      本文标题:给TextView设置compoundDrawable要注意的问

      本文链接:https://www.haomeiwen.com/subject/ykkcmqtx.html