I have an android application in which a user can create what is basically a macro and label that macro with some text. I then create a button for them with their descriptive text. The button is a custom view extending Button
. In the constructor I set the layout as follows:
this.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
These buttons are then placed within a GridView
. Functionally, it's working as intended but I'm running into a layout issue.
If the text is too long, it will break and wrap to the next line, thus increasing the height of the button while maintaining a constant width. The problem is in how the text wraps, it will break in the middle of a word, instead of gracefully wrapping at whitespace. For instance the test "Perform an Action" will render as
Perform an Ac
tion
Ideally, I'd like to wrap gracefully at whitespace instead of breaking words across lines. I suppose I could do this by checking the length of the text and the font against the width of the button and then doing some fancy insertion of newlines myself, but that gives me traumatic flashbacks to making win32 UIs. Is there a better way?