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



3 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
  3. The 7 best Indian casino-casinos in New York (NY) - Mapyro
    The 7 전주 출장마사지 best Indian casino-casinos in New York (NY). Map. 경상북도 출장샵 3. Best Indian casino-casinos in New York 김포 출장안마 (NY). Map. 3. Best Indian 의정부 출장마사지 casino-casinos in New 고양 출장샵 York (NY). Map. 4. Best Indian casino-casinos in

    ReplyDelete