Featured Image

15 quirky Android XML layout parameters to know

February 4, 2013
 · 
1 min read

After working on Android widgets for the last two years I've learned a lot about limitations, inconsistencies, and ghostly parameters in Android XML layout files. Some parameters are simply "overly clever" so I'll offer some standard settings you should use. These suggestions will also help you effectively reduce the plethora of nanny nag warnings in the IDE.

These come in handy so take a moment to review.

(more…)

Comments
Daniel
You missed one of my most often used quirky XML attributes – ScrollView’s fillViewport. Romain Guy explains it pretty well here: http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/
Thomas
Another nastiness is lineSpacingMultiplier – as you said, values below 1.0 may give you overlapping in some fonts. What they almost every time give you however are cropped last lines, because the sdkis unable to determine the correct height of such a multi line text view.
radley
I think you can extra padding on the bottom to compensate.
Thomas
No, that was not working for me. The only way to “fix” this problem was to create my own TextView implementation and let this overwrite onMeasure(). I calculated some “magic height value” that I set as new measured dimensions, which then expanded the text’s box accordingly.
George
FYI textAllCaps is only present on API level 14+. So it won’t work on older Android versions.
That’s actually a good thing, because the unknown params are ignored on lower API levels. Radley said “follows JellyBean’s all caps text style” so if you’re using that you can be sure it doesn’t contradict an older Android’s design. The problem is if you want to have an all-round-same design you have to write code to convert to all caps for compatibility.
Vladimir
One more attribute: android:clipToPadding. Very useful with ListView
Karl
The plural of ellipse might be ellipses, but that is unrelated to the attribute that decides whether to ellipsize (verb) the text.
radley
Ellipsize is not a verb, it’s not even a real word.
Alan
Ellipsize is a neologism (a made up word). But it is definitely a verb. I suppose because it is not found in a dictionary, the author assumed (incorrectly) that it was intended to be the plural of the noun ellipsis. But no, it is a verbification (see, I can make up words, too!) of the noun ellipsis.
Random Teenager
I think maybe they were trying to go with “ellip-size”, if they used “ellipsis” or “ellipses” it might be a it confusing as to what the parameter does.
I think when they created the parameter it was supposed to be a merge of “ellipse” and “size”, hence “ellipsize” – the parameter is not relative to size, but can actually be associated with a parameter that affects “size” of the ellipses. Such as having none, etc…
It is probably verbification, but I’m just bringing forward another idea.
Bengalore
Thanks a big bunch mate. Your | android:adjustViewBounds=”true” | works like a charm including when applied to an image within a (deprecated) Gallery widget :-).
Daniel
keepScreenOn is also not much known.
Emily
Thank you so much for the negative dp idea I was trying so hard to get rid of a space
Thank you for sharing your deep understanding of quirky android jargons, you just saved my hours of experimenting on weird Android attributes.
Mateusz
Thank you for android:includeFontPadding=”false” :)
That solved my problem with stubborn text with ellipsize=”end” that didn’t wanted to center itself vertically. Have a good day!

Leave a Reply to EmilyCancel reply

footer-logo

Twitch   •   Mastodon
Twitter   •   LinkedIn   •   Mixcloud

thank you for visiting  ❤︎
View