Android – Include Other Layout

By -

Problem: How can I include other layouts inside the current XML layout file?
Solution:

Today I came across a great solution that we can also include other layout by using “Include Other Layout” in drag and drop way. Yes earlier i was doing the same by using tag inside the XML layout file. But now it is being automatically generating. I don’t know if it was also generating automatically but I was writing code myself to include other layout.
Purpose:There are many cases where you want to use the existing layout file inside many other layout file, so in that case you can use <include>. In short, it is used to reuse and share other existing layout code.

Step 1:  while designing XML layout, just Drag and drop "Include Other Layout" in UI design area.
Step 2: Clicking on which displays below dialog box, select the layout whichever you want to include inside the current layout file.
Step 3: You are done with <include> inside your current layout file. Just check "Graphical section", you will see the included layout design in your current layout design and  Just check the xml file, you find overthere:
  <include android:layout_height="wrap_content" layout="@layout/second" android:layout_width="wrap_content" android:id="@+id/include1"></include>

I would suggest this link as overthere they have mentioned with the best example: http://developer.android.com/resources/articles/layout-tricks-merge.html

Paresh Mayani

Lazy android developer, exploring the horizon of android development since 7 years, currently working as a Technical Lead - Android at Simform Solutions, India. Former Application Architect at KarConnect. He is the Head/Organizer of Google Developers Group (GDG), Ahmedabad

Loading Facebook Comments ...
Loading Disqus Comments ...