ProgrammerGuide.Net | Step by Step Programmer Guide

Creating A Linear Layout | Android Programming | ProgrammerGuide.Net | Step by Step Guide

LinearLayout is a type of layout from a view group. It helps to arrange the child views in either a vertical or horizontal orientation. Each child view will appear on screen in the same order as in XML.

When you create a project with the BlankActivity template, it includes the activity_main.xml file with a RelativeLayout root view and a TextView child view.

Let’s delete the <TextView> element and change the <RelativeLayout> element to <LinearLayout>. Then add the attribute, android:orientation and set it to “horizontal”.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
</LinearLayout>

match_parent

As you can see in the above example, the root view LinearLayout should fill the entire screen area. This is achieved with the help of the attribute value match_parent. It states that the view should expand its width and height to match the width and height of the parent view

The attributes, android:layout_width and android:layout_height, are required for all views to specify their sizes.

Please click here for related products on Amazon!

Jayashee

Add comment

Want to Check Celebrities News?