Android - Combining Multiple Layouts in a Layout - ANDROID - Helper

Wednesday, March 16, 2011

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/AVvXsEjx-OpmmLlN_hK5IxrjS4oolll_ToyZtqstkn8O4AE1YzHbXB5lVCKjsdd1Gw3ivsP6NEGIOQZy0SNC0_HZ2KaVmhyh4fPxSHtW691KbQ2KUhlhYMRU-hGHqW5WrlLQX9IrWAzGLch475g/

3 comments:

  1. Nice one..For make our task easy we can use relative to construct small blocks and use to construct final layout...

    ReplyDelete
  2. Good info...thanks for sharing / posting!

    ReplyDelete
  3. Thanks to give this answer its very useful for me thank a lot

    ReplyDelete