Adding a Linear Layout

Android Layouts: 1 2 3 4 5 6

By default, Android places all your controls in a type of layout called a Constraint Layout. This is then the used as the parent view for all of your widgets. Another type of layout you can use is called a LinearLayout. We'll use one of these to hold the buttons on our form.

Click on the Layout category in the palette. Locate LinearLayout (Horizontal):

The LinearLayout item in the Android Studio palette

Drag one of these onto your blueprint. Again, your new control will be added to the top left, so you'll need to drag it down below the Image View:

A LinearLAyout added to the Blueprint

Add a constraint by moving your mouse to the top circle of your LinearLayout:

A Constraint Anchor highlighted

When you see the circle turn green, drag to the bottom circle of the Image View:

Dragging a Constraint Anchor to another widget

Now add constraints to the left and right edges of your screen, just like you did before:

Adding left and right constraints to a LinearLayout

Finally, add a constraint from the bottom circle of your LinearLayout to the bottom edge of your screen:

Adding a constraint to the bottom of the screen

It's a bit too narrow to hold buttons, at the moment. To remedy this, have a look at the properties area. Locate the layout_height and change it to 0dp:

Chaning the layout_height property

Your layout will then change size:

LinearLayout in Blueprint view

.

Now that we have a Linear Layout, we'll add some buttons to it. We'll do that in the next lesson below