views:

30

answers:

1

I have for example a Play/Pause button and would like its size not to change when I change the text from 'play' to 'pause' and back. Due to internationalization I don't know if 'play' or 'pause' will be the longer string..

I imagine I need to set the string to the longest string and then create the button allowing the UI to size it properly then get its height/width and set the height/width such that it doesn't resize when the button text is changed to the shorter string. But I'm not sure how/where in the code to do this or if there is an easier way to handle this automatically.

A: 

Most fonts will show characters different sizes, so for example the width of an "a" is not the same as the width of an "m". A small number of fonts handle it ok, but most look good because they have letters of different sizes.

So I think your options are:

  1. Force the size of the button, set it in button in the layout, e.g. android:layout_width="250dp"

  2. Use an icon image instead of text, if you can find imagery that is cross-cultural. I'd expect most media players use icons specifically to avoid this.

If you find the different languages vary a lot you could special-case some of them and use larger buttons for specific languages, but the simple option is usually the best, so if it was me I'd do one of the above two, but whatever you don't assume text strings with the same number of characters will render the same width, that's rarely the case.

Ollie C
I'm going with a combo of #1 and also creating a toggle on/off type button for other cases. Thanks.
Mark