Android Layouts
-----------------
- An Android layout is a class.
- It handles to arrange the components appear on the screen.
- Anything that is a View can be a child of a layout.
- All of the layouts inherit from ViewGroup (which inherits from View) so you can nest layouts.
- You could also create your own custom layout by making a class that inherits from ViewGroup.
Android supports the following ViewGroups:
* LinearLayout
* AbsoluteLayout
* TableLayout
* RelativeLayout
* FrameLayout
* ScrollView
RELATIVE LAYOUT
-----------------------
<?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"
android:layout_gravity="center_vertical"
android:gravity="center" >
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="@string/name" />
<EditText
android:id="@+id/nw_name"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_marginLeft="60dip"
android:layout_toRightOf="@+id/name"
android:text="" />
<TextView
android:id="@+id/degn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/name"
android:layout_marginTop="30dip"
android:text="@string/designation" />
<EditText
android:id="@+id/nw_degn"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_below="@+id/nw_name"
android:layout_marginLeft="20dip"
android:layout_toRightOf="@+id/degn"
android:text="" />
<TextView
android:id="@+id/cmpy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/degn"
android:layout_marginTop="30dip"
android:text="@string/company" />
<EditText
android:id="@+id/nw_cmpy"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_below="@+id/nw_degn"
android:layout_marginLeft="36dip"
android:layout_toRightOf="@+id/cmpy"
android:text="" />
<Button
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/nw_name"
android:layout_below="@+id/nw_cmpy"
android:layout_marginTop="23dp"
android:text="@string/next" />
<Button
android:id="@+id/btn_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/cmpy"
android:layout_alignTop="@+id/btn_next"
android:text="@string/go" />
</RelativeLayout>
TABLE LAYOUT
-------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="vertical" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center" >
<TableRow>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/name" />
<EditText
android:id="@+id/nw_name"
android:layout_width="120dip"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:hint="Name"
android:text="" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/degn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/designation" />
<EditText
android:id="@+id/nw_degn"
android:layout_width="120dip"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:hint="Designation"
android:text="" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/cmpy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/company" />
<EditText
android:id="@+id/nw_cmpy"
android:layout_width="120dip"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:hint="Company"
android:text="" />
</TableRow>
<TableRow>
<Button
android:id="@+id/btn_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/go" >
</Button>
<Button
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/next" >
</Button>
</TableRow>
</TableLayout>
</LinearLayout>
RELATIVE LAYOUT
-----------------------
<?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"
android:layout_gravity="center_vertical"
android:gravity="center" >
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="@string/name" />
<EditText
android:id="@+id/nw_name"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_marginLeft="60dip"
android:layout_toRightOf="@+id/name"
android:text="" />
<TextView
android:id="@+id/degn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/name"
android:layout_marginTop="30dip"
android:text="@string/designation" />
<EditText
android:id="@+id/nw_degn"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_below="@+id/nw_name"
android:layout_marginLeft="20dip"
android:layout_toRightOf="@+id/degn"
android:text="" />
<TextView
android:id="@+id/cmpy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/degn"
android:layout_marginTop="30dip"
android:text="@string/company" />
<EditText
android:id="@+id/nw_cmpy"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_below="@+id/nw_degn"
android:layout_marginLeft="36dip"
android:layout_toRightOf="@+id/cmpy"
android:text="" />
<Button
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/nw_name"
android:layout_below="@+id/nw_cmpy"
android:layout_marginTop="23dp"
android:text="@string/next" />
<Button
android:id="@+id/btn_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/cmpy"
android:layout_alignTop="@+id/btn_next"
android:text="@string/go" />
</RelativeLayout>
TABLE LAYOUT
-------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="vertical" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center" >
<TableRow>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/name" />
<EditText
android:id="@+id/nw_name"
android:layout_width="120dip"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:hint="Name"
android:text="" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/degn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/designation" />
<EditText
android:id="@+id/nw_degn"
android:layout_width="120dip"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:hint="Designation"
android:text="" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/cmpy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/company" />
<EditText
android:id="@+id/nw_cmpy"
android:layout_width="120dip"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:hint="Company"
android:text="" />
</TableRow>
<TableRow>
<Button
android:id="@+id/btn_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/go" >
</Button>
<Button
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/next" >
</Button>
</TableRow>
</TableLayout>
</LinearLayout>
No comments:
Post a Comment