手工設置文本與圖片相對位置時,常用到如下方法:
setCompoundDrawables(left, top, right, bottom)
setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom)
意思是設置Drawable顯示在text的左、上、右、下位置。
但是兩者有些區別:
setCompoundDrawables 畫的drawable的寬高是按drawable.setBound()設置的寬高,
所以才有The Drawables must already have had setBounds(Rect) called.
使用之前必須使用Drawable.setBounds設置Drawable的長寬。
setCompoundDrawablesWithIntrinsicBounds是畫的drawable的寬高是按drawable固定的寬高,
所以才有The Drawables' bounds will be set to their intrinsic bounds.
即通過getIntrinsicWidth()與getIntrinsicHeight()獲得,