2014-10-05 20 views
9

TextView的方法設置drawable的區別在哪裏?文檔非常含糊。TextView添加drawable的不同方法

1) setCompoundDrawables (Drawable left, Drawable top, Drawable right, Drawable bottom) 
2) setCompoundDrawablesRelative (Drawable start, Drawable top, Drawable end, Drawable bottom) 
3) setCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top, Drawable right, Drawable bottom) 
4) setCompoundDrawablesRelativeWithIntrinsicBounds(Drawable start, Drawable top, Drawable end, Drawable bottom) 

在此先感謝。

回答

19

setCompoundDrawables需要調用的Drawable(S)手動setBounds(Rect),而setCompoundDrawablesWithIntrinsicBounds將決定Drawable你的邊界(有點像設置一個ImageViewwrap_content)。

setCompoundDrawablesRelative等同於setCompoundDrawables,除了不使用「左」和「右」,它使用「開始」和「結束」,如果你想支持這是有用的兩個左到右和從右到左側本地化(see this blog post for more info)。同樣適用於setCompoundDrawablesRelativeWithIntrinsicBoundssetCompoundDrawablesWithIntrinsicBounds