Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested XML layout file

Is there a way in android to refer a xml layout file from another layout file. To explain better,

I have a layout file named layout1.xml & layout2.xml. Is it possible for me to refer layout2.xml from layout1.xml

like image 361
Raj Avatar asked Aug 30 '11 05:08

Raj


People also ask

How do you write nested XML?

Prefix each attribute name with the node/tag name of the child element, followed by a '/@' and then the name of the child element's attribute. Create a column for the text/cdata value of the child element. The name of the column will be the node/tag name of the child element.

What is nested layout?

By the term of Nested we mean one Layout inside of other Layout. In Android all layout can be nested one another. In this example we create a Registration Form with multiple fields using Nested Linear Layouts.

What is nested XML?

XML Nested elements means the element within the element. The structure starts with root element within that another element that follows accordingly. Root element is the most outer element. Inside the root element, all the other elements mentioned can have the inner elements.

What an XML layout file contains?

Specifically, Android considers XML-based layouts to be resources, and as such, layout files are stored in the reslayout directory inside your Android project. Each XML file contains a tree of elements specifying a layout of widgets and containers that make up one View.


2 Answers

use this:

<include 
    android:id="@+id/layoutid" 
    layout="@layout/header" />

refer this doc:

http://android-developers.blogspot.com/2009/03/android-layout-tricks-3-optimize-by.html

edit: fixed broken link

like image 105
Vineet Shukla Avatar answered Sep 17 '22 16:09

Vineet Shukla


Yes: you can use include or merge.

edit: broken links fixed

like image 43
Femi Avatar answered Sep 20 '22 16:09

Femi