You can make a xml file for MainActivity
with just a Header
and Footer
, and in the middle a Fragment
, and then just replace any fragment inside that.
Something like below in a RelativeLayout:
<RelativeLayout
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="50dp"/>
<FrameLayout
android:below:"@+id/header"
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:margin_bottom:"40dp" />
<RelativeLayout
android:id="@+id/footer"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="40dp"/>
<RelativeLayout/>
Now to replace a fragment you can use this :
//Your new fragment
Fragment fragment = new PlanetFragment();
//If you want to pass something to it
Bundle args = new Bundle();
args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
fragment.setArguments(args);
// Insert the fragment by replacing any existing fragment
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment)
.commit();
I dont have eclipse installed on my Mac, so sorry if I have error on my xml