I am implementing an Android layout that acts as an instruction manual of sorts. So basically I have several pages that the user can flip through. Let's say I implemented it like this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/page_1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Put stuff for page 1 -->
</LinearLayout>
<LinearLayout
android:id="@+id/page_2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="INVISIBLE">
<!-- Put stuff for page 2 -->
</LinearLayout>
<LinearLayout
android:id="@+id/page_3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="INVISIBLE">
<!-- Put stuff for page 3 -->
</LinearLayout>
<!-- ... -->
<LinearLayout
android:id="@+id/page_N"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="INVISIBLE">
<!-- Put stuff for page N -->
</LinearLayout>
</FrameLayout>
Basically how I would simulate the "page flipping effect" (perhaps with animation) is to make the current page invisible and make the new page visible. However, this implementation has some problems:
- Since I'm basically loading all the pages at the same time, the Activity holding this layout will use up a lot of heap, especially if there's background images involved.
- The above problem is going to get worse as I expand the manual.
- I've considered splitting the pages into separate activities, but that seems a bit excessive and too troublesome.
I was thinking if there's a way to dynamically load a page from an XML file during run time. As in, would it be possible to inflate a particular layout whenever the user demands it? Or if anyone has a better implementation that I haven't though of, please tell me!