Home and Learn: Android Course


Android Layouts

In our previous project, we just used the default widget, which was a Text View that displayed the text "Hello World". We'll now explore ways you can design smart-looking layouts with Android Studio. The layout you'll design in this section looks like this in portrait view:

A layout in portrait mode

And like this in landscape:

A layout in landscape mode

Let's get started.

Create a new project for this. Click File > New > New Project from the Android Studio menu at the top. If you're just opening Android Studio, click the button at the top that says New Project. Select the Empty Views Activity, rather than the default Empty Activity. Click Next and call your project Quiz Layout, making sure that Java is selected as the language:

The New Project dialogue box in Android Studio

Click Finsih to create your new project.

Once your project loads, make sure that the activity_main.xml file is displayed. If it's not, in the Project Files area on the left, expand the res > layout item and double click activity_main to open the file in the editor window (you can close down the Java file):

Project Files area of Android Studio showing the activity_main.xml highlighted.

 

 

Now let's have a look at the Designer, and the toolbar icons you'll use most frequently.

Notice the Code, Split, Design buttons in the top right of Android Studio:

Make sure the Design item is selected, and take a look at the icons at the top of the designer:

App toolbar icons highlighted in Android Studio.

The icons highlighted by a red square in the image above are as follows:

Toolbar icons for an app in Android Studio.

Notice, too, the Design/Blueprint menu just above the highlighted options:

Design/Blueprint options in Android Studio.

The item on the menu that is selected, Design and Blueprint, will display what your app looks like and a blueprint of the app. Blueprint mode is useful for fiddling about with the positioning of the controls you place on on your app. If you want to hide the Blueprint or Hide the Design, select the appropriate item on the menu.

If you hover your mouse over either the Design or the Blueprint version of your app (the two big rectangles), the zoom controls appear. These ones:

Zoom Controls in Android Studio.

Try them and see what they do,

Two more areas to examine are the Palette:

Palette in Android Studio 3

and the Component Tree:

he Component Tree in Android Studio.

The Palette is where you drag and drop controls onto your design surface. The Component Tree shows you a list of controls that you have dropped on your design surface. You can click an item in the Component Tree to select it in the designer.

In the next lesson, you'll start adding widgets to your Android layout.

Back to the Android Contents Page

 


Email us: enquiry at homeandlearn.co.uk