Building a menu with LinearLayout
LinearLayout
is probably the simplest layout that Android offers. As the name suggests, all the UI items within it are laid out linearly. You have just two choices—vertical and horizontal. By adding the following line of code (or editing via the Attribute window), you can configure a LinearLayout
to lay things out vertically:
android:orientation="vertical"
You can then (as you could probably have guessed) change "vertical"
to "horizontal"
to lay things out horizontally.
Before we can do anything with LinearLayout,
we need to add one to a layout file. And, as we are building three layouts in this project, we also need a new layout file.
Adding a LinearLayout to the project
In the project window, expand the res
folder. Now right-click the layout
folder and select New. Notice that there is an option for Layout resource file, as shown in the following screenshot:
Select Layout resource file and you will see the New Resource File...