Thursday, April 12, 2012

Android - Combining Multiple Layouts in a Layout


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/AVvXsEj-ZoyDeC-3WOdZlKlBED3sn9EUucBZ50DIuSs7614z0LfIYifCANMaU-nrWYYbOQKUag5V8xs7Rz9Y-W5AuclX7z903kAyTqoYhRFSOILa28xMD-MKl8Hups4ZuBkJWiW53RTylXd6cAI/

No comments: