Friday, June 22, 2012

Android - Combining Multiple Layouts in a Layout


COMBINING LAYOUTS IN A LAYOUT

The main.xml file is

<?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="Layout 1" />
<include android:id="@+id/cell1" layout="@layout/layout1" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Layout 2" />
<include android:id="@+id/cell2" layout="@layout/layout2" />
</LinearLayout>

The layout1.xml file is

<?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="wrap_content"
android:background="#ff0000" >
<TextView android:layout_width="fill_parent"
                                android:layout_height="40px"
android:text="TextView" />
                <EditText android:layout_width="250px"
android:layout_height="wrap_content"
                                android:hint="EditText" />
                <CheckBox android:layout_width="fill_parent"
                                android:layout_height="40px"
android:text="Checkbox" />
</LinearLayout>

The layout2.xml file is

<?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="wrap_content"
android:background="#00ff00" >
<TextView android:layout_width="fill_parent"
                                android:layout_height="40px"
android:text="TextView" />
                <EditText android:layout_width="250px"
android:layout_height="wrap_content"
                                android:hint="EditText" />
                <CheckBox android:layout_width="fill_parent"
                                android:layout_height="40px"
android:text="Checkbox" />
</LinearLayout>

The OUTPUT will be

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcksSror-I5w632te0n8PFX1E0RUmIY2kYP4kBknMuHDCB5GWRzullHyNvAY-CgtV01JcPUsJv2DsyFAVYxF_ofBe2XlkkzoHuT-5H8jWm9RyGME3MV7qJg4zZQb5sZcCDE2cjRezPk7A/