You could have your layouts in a single xml file. The ones you don't want to see immediately, set android:visibility="gone"
in the XML, and at runtime you would do a call to hiddenView.setVisibility(View.VISIBLE);
.
Your XML would look something like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/layout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
<LinearLayout android:id="@+id/layout2"
android:visibility="gone"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
</RelativeLayout>
at runtime you could do:
layout1.setVisibility(View.GONE);
layout2.setVisiblity(View.VISIBLE);
This would essentially create the appearance of the layouts swapping.
I believe this would also work if you have shared objects between the two layouts. Just make sure you set the id first using android:id="@+id/view1"
and every subsequent setting of this id you would do android:id="@id/view1"
(without the +).
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/layout1"
android:layout_width="fill_parent">
<View android:id="@+id/view1"/>
</LinearLayout>
<LinearLayout android:id="@+id/layout2"
android:visibility="gone"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<View android:id="@id/view1"/>
</LinearLayout>
</RelativeLayout>