Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Disclaimer</strong></p> <p>This is where fragments can get tricky. The problem would be simple if Activity 1 &amp; 2 had identical layouts so that you could simply attach/detach fragments and use the fragment back stack to unwind.</p> <p>Because you want 2 unique layouts to house your fragments, things are going to be a little more involved. If at all possible I would try to use the same layout so that you can take the easy path.</p> <p>As another option, you could use two activities as you outline above and send data back and forth with Intents.</p> <p>That said, if I really had to implement this solution as written, here is what I would do. <em>Note</em> that I am not advocating this solution but myself do not know of a better way of doing things.</p> <p><strong>The Solution</strong></p> <p>Create a FragmentActivity whose view would be Main Screen as you've defined above. The layout for the Main Screen would contain:</p> <ul> <li>Left nav bar</li> <li>Top bar</li> <li>2 layouts. layout1 and layout2. These would be contained in a parent layout i.e. RelativeLayout or LinearLayout and would contain the necessary FrameLayout elements for your fragments.</li> </ul> <p>Example using your XML (note, tags are a bit brief):</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:background="#9ccc" &gt; &lt;!-- Top Bar --&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:id="@+id/layout1"&gt; &lt;FrameLayout android:id="@+id/listFragment" /&gt; &lt;FrameLayout android:id="@+id/contentFragment" /&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:id="@+id/layout2"&gt; &lt;FrameLayout android:id="@+id/imageFragment" /&gt; &lt;FrameLayout android:id="@+id/boxFragment1" /&gt; &lt;FrameLayout android:id="@+id/boxFragment2" /&gt; &lt;FrameLayout android:id="@+id/boxFragment3" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>The main idea is that you then show/hide layout1 &amp; layout2 i.e. set android:visibility="gone" based on the state of your app.</p> <p>The disadvantages of this method are:</p> <ul> <li>Using fragment backstack may be impossible, instead you'll have to track where the user is in your UI flow and manage the back button to show/hide layout</li> <li>You may need to take special care to attach/detach fragments when you show/hide their parent view to reduce resource consumption while the fragments are invisible</li> </ul> <p>The advantages are:</p> <ul> <li>Easy communication between fragments and the base activity since only 1 activity is used</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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