What is Layout?



Layout : It is used to arrange components in some predefined manner is known as a layout.Linear Layout : To arrange the component linearly is known as LinearLayout. LinearLayout arranges the componentss in single layout that is in a vertical line (column) or in a Horizontal Line(Rows).

Android framework provides a classs by the name linear layout this class provides us some constructor to initialize this class and some methods to interact with object of this class.

Commonly used constructor and methods of LinearLayout are as follows:

1.    public LinearLayout(Context ctx)
{
--------------------
}

E.g. LinearLayout ll = new LinearLayout(this);

# setOrientation(int Orientation);
Method of LinearLayout is used to set orientation of layout that is whether the components are arranged in vertically of in horizontally.
LinearLayout class provides us some state find integer constant which are used by application developer to set orientation of layout.

Signature :
public void setOrientation(int Orientation)
{
------------------------------
}

publiic static final int HORIZONTAL = 1;
public static final int VERTICAL = 2;

The constant 1 is used to arrange horizontally and the constant 2 is used to to arrange vertically.

Example :
ll.setOrientation(LinearLayout.HORIZONTAL);
Components of layouts will be arranged horizontally

ll.setOrienation(LinearLayout.VERTICAL);
Components of layouts will be arranged vertically

Note: Default orientation of LinearLayout is horizontal.

# setOrientation(LayoutParams lp);
Method is used to set the parameters that is the width, height and weight of Linearlayout. This method receives the reference of LayoutParams as a parameter.

Signature:
public void setLayoutParams(LayoutParams lp)
{
}

E.g.  LayoutParams lp = new LayoutParams(LayoutParams.fill_parent, LayoutParams.wrap_content);
ll.setLayoutParams(lp);

Let we want to create a layout as given below:
LinearLayout projects-codes.blogspot.in

The xml code will be as follows given below:

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

<LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout2" android:layout_height="wrap_content" android:weightSum="1.0">
<TextView android:text="Name" android:id="@+id/textView1" android:textSize="25sp" android:layout_weight="0.7" android:layout_width="match_parent" android:layout_height="wrap_content"></TextView>
<EditText android:text="" android:id="@+id/etName" android:layout_width="match_parent" android:layout_weight="0.3" android:layout_height="wrap_content"></EditText>
</LinearLayout>

<LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout2" android:layout_height="wrap_content" android:weightSum="1.0">
<TextView android:text="Job" android:id="@+id/textView1" android:textSize="25sp" android:layout_weight="0.7" android:layout_width="match_parent" android:layout_height="wrap_content"></TextView>
<EditText android:text="" android:id="@+id/etJob" android:layout_width="match_parent" android:layout_weight="0.3" android:layout_height="wrap_content"></EditText>
</LinearLayout>

<LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout2" android:layout_height="wrap_content" android:weightSum="1.0">
<TextView android:text="Salary" android:id="@+id/textView1" android:textSize="25sp" android:layout_weight="0.7" android:layout_width="match_parent" android:layout_height="wrap_content"></TextView>
<EditText android:text="" android:id="@+id/etSal" android:layout_width="match_parent" android:layout_weight="0.3" android:layout_height="wrap_content"></EditText>
</LinearLayout>

<LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout2" android:layout_height="wrap_content" android:weightSum="1.0">
<Button android:text="Save" android:id="@+id/btnSave" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight=".33"></Button>
<Button android:text="New" android:id="@+id/btnNew" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight=".34"></Button>
<Button android:text="Exit" android:id="@+id/btnExit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight=".33"></Button>

</LinearLayout>

</LinearLayout>

android:weightSum is the attribute of Layout used to set width in percentage.
android:layout_weight is attribute of components(Button, TextView, EditText etc.)



Application tools need for android app development


Application tools need for android app development.

To develop android apps we need android SDK contains the API libraries and developer tools to build, debug and develop android apps.

If you are new to develop android apps then you must use ADT Bundle to quickly start android app development.

You can download it from developer.android.com site click here to go >> Download Eclipse ADT

Directory Structure of Android

Directory Structure of Android :
The arrangement of folders in any android application is known as directory structure of android.
The directory structure of android is given below :




Directory src :
This directory contains the source code of any application with ".java" extension.

Directory gen :
This directory contains the auto generated R.java file which is reusable java file.
R.java is also know as reusable java class. It is an auto generated java file that means we can not modify this class manually or by hand.

This java file is generated by AAPT(Android Asset Packaging Tools). This tool receives resource data as an input and generate R.java file as an output.
R.java file works as a mediator file between activities and xml components defined inside resource.
R.java file contains some static final inner classes like drawable, layout, id, etc...

Directory res :
 The res directory is known as resource directory. It contains drawable-ldpi, drawable-mdpi, drawable-hdpi, these drawable directory is contains the image resources like icon and other images with .png extension.
Directory layout contains xml files (User interface designed by developer)  the user interface is designed using xml code in android.

Directory value :
It is used to put data in form of key value pair.

AndroidManifest.xml
It is a meta data file which is used by ARE(Android Runtime Environment) to launch application.