I can't figure out how to set the alignment of text and its compound drawable (smaller than text) in a TextView. It seems the default alignment is center, but I need to align them by the edge.
PS: The android:gravity
works great if compound drawable is larger than text, but not if smaller.
It’s almost as easy to set these drawables from code: textView.setCompoundDrawablePadding (…); With this idea in mind, we can create very interesting layouts. Let’s create a simple username and password form: Quite easy.
The default text alignment of text in TextView is left. Note: When you specify text alignment, it takes effect only when the width of TextView widget is more than the width of text. In other words, the size of container should be greater than the size of content, or, if the text spans multiple lines.
Third TextView – Width of the widget wraps the content, which is the text. But as text spans multiple lines, the text is effectively displayed with center alignment.
You can use center_vertical | center_horizontal value to set the text at the center of the TextView area. HTML, HTML5. CSS, CSS3 Color Codes 2020 - Html
It sounds like you're using an image with fixed dimensions for android:drawableLeft
.
Try using a nine-patch or defining a drawable through an XML resource file. In this way your drawable's dimensions will stretch to align in the TextView
the way that you want it to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With