title: Multiple fragments in a vertical Linearlayout
body: <p>I am facing the following issue in my app. I want to add multiple fragments into a vertical LinearLayout in a certain order. </p>
  
  <p>Here is my layout</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/scrollview"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:fillViewport="true" &gt;
  &lt;LinearLayout 
      android:id="@+id/content"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical" &gt;
  &lt;/LinearLayout&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>And here is the code I use to add the fragments.</p>
  
  <pre><code>Fragment fragment1 = MyFragment.newInstance(param1);
  Fragment fragment2 = MyFragment.newInstance(param2);
  
  FragmentManager fm = getSupportFragmentmanager();
  
  fm.beginTransaction().add(R.id.content, fragment1, "fragment1").commit();
  fm.beginTransaction().add(R.id.content, fragment2, "fragment2").commit();
  </code></pre>
  
  <p>I use one transaction each time so I guarantee that they are placed in that order on screen.</p>
  
  <p>My problem is that when the orientation changes and the Activity is re-created there is no way I can be sure that they will appear on screen in the same order.</p>
  
  <p>Has someone experienced this too? How can I solve the problem? Having two layouts inside the LinearLayout with an specific id for each of the fragments will not help, because the number of fragments I have to add is undetermined (I just used the number 2 for the example)</p>