If I have a layout called bottom.xml,
bottom.xml:(simply contain a textview and edit text view)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:text="@string/username"
/>
<EditText
android:id="@+id/name"
android:layout_width="120dip"
android:layout_height="50dip"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
Is there any way to embed the above bottom.xml layout inside other layouts instead of repeatly writing the same code in several layout files (when other layouts have a part which contains the same layout as bottom.xml)?
For example, if my admin.xml layout also contain part of the layout which looks exactly the same as bottom.xml, how to just embed the bottom.xml inside admin.xml instead of writing the same code again?
admin.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
...
...
<!--How to embed bottom.xml here-->
...
</LinearLayout>
If there is no way to do it in Android, what could be the workaround??
----------Update-----------
Like @xevincent suggested, I can reuse the bottom.xml by use <include>
tag,
But How to change the id of the elements inside the resued layout?
For example, insdie bottom.xml, I would like to change the id of <editText android:id="@+id/name">
to <editText android:id="@+id/other_name">
when I reuse the bottom.xml layout in other layout, how to change the id ?
Just upvote xevincent's anwser. I added this answer because SO recommends to "Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline."
So, basically, his link explains that you should use
<include />
.And know that you can override the layout parameters:
Have a look on this doc, Link updated
http://android-developers.blogspot.com/2009/02/android-layout-tricks-2-reusing-layouts.html
See this doc reusing layouts.