The optimum layout for controls might depend on the orientation. If I have a set of checkboxes or radio buttons they might fit well if I stack them vertically when the user holds the phone in a vertical orientation. But if the user flips to horizontal it might be better to arrange them into two shorter stacks side-by-side, instead of forcing the user to scroll.
Does Android have any UI guidelines that address whether it's acceptable to use different layouts for vertical and horizontal? And if so, how would I implement it to use the same controls, i.e., the same ID's for both layouts?
Thanks in advance!
LinearLayout is perfect for displaying views in a single row or column. You can add layout_weights to the child views if you need to specify the space distribution. Use a RelativeLayout, or even better a ConstraintLayout, if you need to position views in relation to siblings views or parent views.
Horizontal layout and Vertical layout are among the views that are most commonly used to design a user interface. Used in conjunction, the Horizontal and Vertical layout views provide the majority of the flow layout capabilities, which you can use to design complex user interfaces.
It is completely acceptable to use different layouts for horizontal and vertical. This is why Android provides the layout and layout-land folders for defining these.
If it makes sense to you and will be easier for the user to navigate, then do it.
To implement this, you create an xml file with the same name in both the layout and layout-land folders. You then specify the same android:id for each asset. For instance a textview would contain the same id in both xml files:
<TextView android:text="@string/SomeText"
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
It's that simple.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With