Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 935
skywall Avatar asked Oct 05 '14 16:10

skywall


People also ask

How do you add text in drawable?

How to put text in a drawable ? Basically, you have to extend the class Drawable and set the canvas to draw the text to a drawable. As you override the draw method, it will take the canvas and draw the text on defined locations.

Can you have multiple styles inside TextView?

Use multiple widgets if you need precise placement of discrete bits of text. Use inline markup if you, um, need markup inline in a widget. Remember: there is no FlowLayout in Android, so stringing together multiple TextViews to create a paragraph is not truly practical AFAIK.


1 Answers

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.

like image 88
bmat Avatar answered Sep 20 '22 21:09

bmat