skywall
skywall

Reputation: 4005

TextView different ways to add drawable

where is the difference between TextView's methods to set drawable? Documentation is quite vague.

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)

Thanks in advance.

Upvotes: 32

Views: 8777

Answers (1)

bmat
bmat

Reputation: 2153

setCompoundDrawables requires you to call setBounds(Rect) on the Drawable(s) manually, whereas setCompoundDrawablesWithIntrinsicBounds will determine the bounds of the Drawable for you (kind of like setting an ImageView to wrap_content).

setCompoundDrawablesRelative is identical to setCompoundDrawables, except rather than using "left" and "right", it uses "start" and "end", which is useful if you want to support both left-to-right and right-to-left localizations (see this blog post for more info). Same applies to setCompoundDrawablesRelativeWithIntrinsicBounds and setCompoundDrawablesWithIntrinsicBounds.

Upvotes: 60

Related Questions