Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7421557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:25:50+00:00 2026-05-29T08:25:50+00:00

I just need someone to tell me if I understood correctly when to use

  • 0

I just need someone to tell me if I understood correctly when to use <include> and when <merge>.

So, I make a header layout which I want to include into some other XML layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Header text" />
</LinearLayout>

And I include it into some other XML this way (which is pretty basic):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <include
        android:id="@+id/header"
        layout="@layout/top"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

This will work well, no issue about it. But in order to optimize the code, I have to use <merge> in the layout which gets included. So the top layout should not have a tag <LinearLayout> but it must look like this:

<merge xmlns:android="http://schemas.android.com/apk/res/android">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Header text" />
</merge>

Have I understood this correctly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:25:51+00:00Added an answer on May 29, 2026 at 8:25 am

    Yes you understood it correctly. merge is used as pseudo parent element to reduce the number of levels in view trees.
    Just check this link, it gives very good explanation of merge.

    In your header file:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <include
            android:id="@+id/header"
            layout="@layout/top"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>   
    

    <LinearLayout> doesn’t make any difference when your file is included in other file you mentioned. So it’s a good thing to use merge instead.

    Since in XML you must use a single parent element and the rest of the XML elements should be included in it, you should use merge as single parent element and can avoid adding unnecessary parent layout.

    Just avoid ‘merge’ when you want to apply a layout differently than layout is defined in file in which your content is inclded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to install Apache Bench on Windows, can someone tell me which MSI
I think I just need someone to show me the obvious. I have a
Just discovered Comet, and am very confused. Can someone tell me what the consensus
I need to use a xml pull parser. I can find stax-api.jar which seems
Just need some quick clarification I have 2 Queries in my Access Database that
Just need a little bit of Javascript to warn people that press the back
Just need get some vals located in application.ini(main ini) in the Controller plugin I
I just need a help in configuring hiberclipse for my eclipse indigo version. Install
I just need to know if WCF is platform independent like Webservices? Can the
I just need to be pointed in the right direction - I can research

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.