Monday, March 28, 2011

In Android import xml into another xml

Its very common in the UI design that some common element appear many time.
Just like some common signature in all the activities (pages) and all.
Its common that we need to set some component as reusable component.

In this case we can use the <include /> tag. This element does exactly what its name suggest.
To use this is very simple
Declare the reusable component as one layout in the /res/layout, let say commonlayout.xml
Then where ever you need to refer this you can use the following code
<include android:id="@+id/id" layout="@layout/commonlayout"/>
Note that:
  • Here you can override all the layout parameters. This means that any android:layout_* attribute can be used with the <include /> tag
  •  If you want to override the layout dimensions, you must override both android:layout_height and android:layout_width you cannot override only the height or only the width. If you override only one, it will not take effect. (Other layout properties, such as weight, are still inherited from the source layout.)
Refer Creating Reusable UI Components



2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. nice
    but it's so short for beginners to understand easily
    plz add some eyample link with it

    ReplyDelete