Monday, May 11, 2015

Non-breaking space

You just finished implementing the UI and sent the screenshot to your designer for review. This is the feedback: "Can we make sure we don't have a dangling last word? Like what I photoshopped in the second box?"

You scratched your head and thought, how do I do that? And then you remember your best friend from HTML:  . Futhermore, you remember a post from a while ago:

  stands for non-breaking space, and you can insert that into your Android XML by \u00A0 or  . I prefer   because Android Studio highlights it with blue:

This way Android will make sure the last two words are always on the same line.

Source code

https://github.com/chiuki/advanced-textview under NonBreakingSpaceActivity.

No comments:

Inline coding questions will not be answered. Instead, ask on StackOverflow and put the link in the comment.

Post a Comment