写界面时有时候会用到drawableRight、drawableLeft等显示给TextView添加Drawable,可能会随着项目逻辑流程等进行需要隐藏这些Drawable,setCompoundDrawables的使用恰好很完美的解决了这一问题。
setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom)
函数解读:
可以在上、下、左、右设置图标,如果不想在某个地方显示,则设置为null。但是Drawable必须已经setBounds(Rect)。意思是你要添加的资源必须已经设置过初始位置、宽和高等信息
如果设置Drawable之后图片不显示,在setCompoundDrawable前加上
drawable.setBounds(0, 0, unFollowIcon.getIntrinsicWidth(), (int) (unFollowIcon.getMinimumHeight()));