I have a form that I want to display in a single column of:
account name
______________________
password
______________________
[ connect ]
when horizontal space is limited (i.e. portrait orientation). And I want it to flow into a two column orientation when horizontal space is abundant:
account name _________________
password _________________
[ connect ]
I know you can do this with a pair of layout resources, but I would like to only have one layout with a dynamic number of columns.
This may not be a useful example, but the approach might prove useful.
First, the
GridLayoutThen I have two integer resource files,
values-large-land-v11/integers.xmlhas<integer name="create_account_pane_column_count">2</integer>andvalues/integers.xmlhas<integer name="create_account_pane_column_count">1</integer>. This gives dynamic columns, where there is one column unless the device and orientation matches large land v11 (7″ tablets and above in landscape orientation).Finally, to get the labels to align nicely (i.e centered when stacked and right aligned when inline) I set it programmatically since the xml value didn’t seem to accept a resource (neither integer nor string).
Also call
alignLabels()in theonCreateoronCreateView(forFragments) to set the gravity on the initial page layout.Side note: my labels use my accent color when their associated field has focus if you notice that.