Home‎ > ‎android‎ > ‎

Layout


This program is an enhance version of HelloWorld program. The different is in the screen layout. The program contains four label text, four text box / Input Text, and one button.

For clearly description, this code resulted from command bellow:

activitycreator -out Layout com.iftitah.android.layout.MyLayout

The comamnd generate folder Layout in the current directory. In the Layout directory, you will find src/, res/, bin/ subdirectory, AndroidManifest.xml, and build.xml file. All the directory and file contains information needed to build android program.

The program contains package com.iftitah.android.layout, and has one activity name MyLayout.

Main.xml at Layout/res/layout contains xml definition like 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"
>
<TextView 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="Hello World, MyLayout"
/>
</LinearLayout>


if we compile this code, and installed to emulator, the program will show just like a HelloWorld program. So, we change the xml definition like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView id="@+id/lblName"
android:layout_width="80sp"
android:layout_height="24sp"
android:text="Name"
/>
<EditText id="@+id/txtName"
android:layout_width="200sp"
android:layout_height="24sp"
android:layout_alignTop="@id/lblName"
android:layout_toRight="@id/lblName"
android:text=""
android:singleLine="True"
/>
<TextView id="@+id/lblAddress"
android:layout_width="80sp"
android:layout_height="24sp"
android:layout_below="@id/txtName"
android:text="Address"
/>
<EditText id="@+id/txtAddress"
android:layout_width="200sp"
android:layout_height="24sp"
android:layout_alignTop="@id/lblAddress"
android:layout_below="@id/txtName"
android:layout_toRight="@id/lblName"
android:text=""
android:singleLine="True"
/>
<TextView id="@+id/lblHome"
android:layout_width="80sp"
android:layout_height="24sp"
android:layout_below="@id/txtAddress"
android:text="Home "
/>
<EditText id="@+id/txtHome"
android:layout_width="200sp"
android:layout_height="24sp"
android:layout_alignTop="@id/lblHome"
android:layout_below="@id/txtAddress"
android:layout_toRight="@id/lblName"
android:text=""
android:singleLine="True"
/>
<TextView id="@+id/lblMobile"
android:layout_width="80sp"
android:layout_height="24sp"
android:layout_below="@id/txtHome"
android:text="Mobile "
/>
<EditText id="@+id/txtMobile"
android:layout_width="200sp"
android:layout_height="24sp"
android:layout_alignTop="@id/lblMobile"
android:layout_below="@id/txtHome"
android:layout_toRight="@id/lblName"
android:text=""
android:singleLine="True"
/>
<Button id="@+id/btnSave"
android:layout_width="80sp"
android:layout_height="24sp"
android:layout_below="@id/txtMobile"
android:text="Save"
/>
</RelativeLayout>




Was this information helpful ?

ċ
Layout.zip
(17k)
Agus SA,
Jun 13, 2009, 6:47 AM
Comments