In
Android, there are various types of layouts available which are used to design
the screen or we can say, are used to arrange the order of various
widgets(like- TextView, EditText, Button, Image, ImageButton etc.) in the
required manner. In Android terms, the layouts are called as ViewGroups and
widgets are called as Views.

The wise use of different layouts in the screen
can reduce the development time and effort and even can save you from the later
stage issues (like- inserting more widgets in the screen in later stage,
porting to different screen resolutions, we will discuss it in the upcoming
posts).

So,
Lets start understanding the behavior of different layouts:

Linear Layout:

Linear layout arranges all the children
widgets in one direction like- vertical or horizontal as shown in the image.

So,
where ever we want some widgets to be aligned in a single direction, we can
make use of Linear Layout.

Remember
that designing the android screen goes from top to down fashion.

Android
has given three amazing properties- wrap_content,
match_parent, fill_parent
to declare the height and width of the layouts and widgets. The one should make
use of them very wisely. Never practice declaring the absolute height and width
of any view. The best way is to use property wrap_content maximally.

Relative Layout:

Relative layout arranges the children
widgets relative to the parent layout or relative to each other. Best way to
understand it, look at the image.

Table Layout: Table layout arranges the children
widgets in the table, i.e. rows and columns, look at the image.

Frame Layout:

Frame layout arranges the children
widgets relative to top left point. In this way, the widgets may get overlapped
as shown in the image.

Absolute Layout: Absolute layout pins the children widgets
in the coordinate points as shown in the image.

However,
this layout is advised not to practice as it raises the issues while designing
the same layout for different screen resolutions. Even it has been deprecated
in the latest versions of Android.

Thursday, September 6, 2012

A checkbox is a specific type of two-states button that can be either checked or unchecked.We will learn how to use checkbox in this tutorial.Note: You should know how to use Buttons and TextViews , if you do not know then read this post Using Buttons and TextViews in Android.Create a new project.Name your activity "CheckBoxActivity"

Editing main.xml file :

open main.xml file and add TextViews, CheckBoxes and Buttons, it should like like below. (you can just copy the below code and paste in main.xml file)

Some times while working with android we need to send some data from one Activity to other.
Here we will create a project which will have two activities "FirstActivity" and "Second Activity".
We send Name and Phone Number from FirstActivity to Second Activity and display the sent data.

Create a new project.

Donot forget to add SecondActivity in manifest.

Editing main.xml file

Edit your main.xml file add two textviews, two edittexts, and a button.
It should look like (you can just copy the following xml code and paste in main.xml file)