Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different Layouts for Horizontal and Vertical for an Android app?

Tags:

android

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!

like image 973
Peter Nelson Avatar asked Dec 31 '10 22:12

Peter Nelson


People also ask

What is the best layout for Android?

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.

What is vertical and horizontal layout?

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.


1 Answers

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.

like image 153
Error 454 Avatar answered Oct 19 '22 04:10

Error 454