Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing a dynamic Android layout
    text
    copied!<p>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:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;LinearLayout android:id="@+id/page_1" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;!-- Put stuff for page 1 --&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:id="@+id/page_2" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="INVISIBLE"&gt; &lt;!-- Put stuff for page 2 --&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:id="@+id/page_3" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="INVISIBLE"&gt; &lt;!-- Put stuff for page 3 --&gt; &lt;/LinearLayout&gt; &lt;!-- ... --&gt; &lt;LinearLayout android:id="@+id/page_N" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="INVISIBLE"&gt; &lt;!-- Put stuff for page N --&gt; &lt;/LinearLayout&gt; &lt;/FrameLayout&gt; </code></pre> <p>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:</p> <ol> <li>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.</li> <li>The above problem is going to get worse as I expand the manual.</li> <li>I've considered splitting the pages into separate activities, but that seems a bit excessive and too troublesome.</li> </ol> <p>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!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload