I’m currently experimenting with the code of Bad Metronome. Since I’m developing natively on a tablet, I need to create the UI by manually editing the XML files, without the support of a user inteface designer tool. Which turned out to be a rather time consuming task. Here are a couple of hints.
Dynamic distribution of widgets
I just wanted to stack three UI elements one above another. I’m using one of the most basic layouts, the LinearLayout in vertical direction. To distribute the widgets equally over the available height, regardless of the screen’s size (handset, tablet), I added empty views above, below, and between the widgets with only the following attributes:
One of the three widgets is a TextView. The amount of lines changes during runtime from one up to three. This means the other user interface elements are repositioned while the user interacts with the app. Fortunately, the TextView provides attributes for the amount of minimum and maximum lines:
Icons for ToggleButton
The ToggleButton supports different icons depending on its state. Those can be changed using a selector:
The content of the selctor file may contain the following lines, where the icons name are just files within the resource folders: