Home Tutorials Hints & Tips

Getting Started in Android Development

Part 6 - Formatting the Linear Layout

In this tutorial we touch on the subject of formatting the Linear Layout. Currently each of the views are located under one another with no space between them. What we can do is apply XML attributes to each view to positioning it on the screen, add color, size text, apply background images and much more. With respect the XML attributes, since all Android views are children of the parent class View, the same XML attributes can be applied to all types of views. A comprehensive description of the Android View class can be found here and it is well worth taking some time look.

In my example, I applied some padding to the Linear Layout using the attribute below:


This pushed all views in 12dp from the edge to set padding around the layout. I then pushed the top most view, the first EditText down 20dp using the attribute below.


All remaining view were given a 10dp spacing.

The EditText views also have a “hint” attribute applied to them. The text entered here allows the developer to set a prompt as to what the user should enter.

android:hint="<hint text>"

The only other attribute applied to this layout was to move the button centrally on the screen by applying the attribute below.


It is a good idea for you to explore these attribute and understand their behaviors. The subject of density pixels, the “dp” used for spacing, needs special attention and is covered in tutorial here. We will apply more XML attributes to this layout later on when we apply some color.

After this tutorial your activity_main.xml layout should look similar to the one below.

Download Download tutorial set 1

Privacy and Cookies Disclaimer Copyright
© 2015 - 2018 North Border Tech Training All rights reserved