Include + Merge Layouts






Merge Layout

  • <merge> is used for optimizing layouts.It is used for reducing unnecessary nesting.
  • when a layout containing <merge> tag is added into another layout,the <merge> node is removed and its child view is added directly to the new parent.

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/add"/>

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/delete"/>

</merge>

Include Layout

Inside the layout to which you want to add the re-usable component, add the <include/> tag. For example, here's a layout that includes the title bar from above:


  <include 
            android:id="@+id/some_id_if_needed"
            layout="@layout/some_layout"/>






Comments

Popular posts from this blog

BottomNavigationView

UPI Payment Integration Android

Clean Code in 2026: Why "Good Enough" Isn't Good Enough Anymore