Android Layouts: 1 2 3 4 5 6
In the previous lesson, you added a Linear Layout to your design surface. We'll now add two buttons to this layout.
Go back to the palette. Click on the Widgets category and locate the Button item. Drag two of these onto your LinearLayout.
If you don't get this right, and have to undo, you can drag widgets onto the Component Tree instead:
You can even rearrange your widgets in the Component Tree. In the image below we've put button 6 before button 5:
With the top button highlighted, drag down to below the bottom button:
Your blueprint area should now look like this:
Select the first button. In the properties area on the right, locate the text property and enter London Bridge:
(The name of your button will probably not be button5.)
Now select the second button and change the text property to Tower Bridge. Your blueprint will then look like this:
Almost done, now.
You can change the background colour of the ConstraintLayout to something other than white.
Go back to design view by clicking the icon in the toolbar:
In the Component Tree, click on the ConstraintLayout item to select it:
Now look at the properties area on the right. Click on the link at the bottom that says View all properties:
You'll then see a fuller list of properties.
Locate the Background property and click just to the right of the word Background, where the white box is in the image below:
Click on the grey square to bring up a dialogue box. Select Color from the left:
Select a colour from the list and click OK. We've chosen holo_blue_dark.
Try it out now. Run your app and see what it looks like. You should see something like this:
Rotate your device and you'll see that the buttons in the layout expand to fill the space:
In the next lesson, you'll learn about the XML file. You'll also learn how to add XML strings. This is quite easy!