Note that there are some explanatory texts on larger screens.

plurals
  1. POOptimize layout during Fragment replacement in FragmentActivity
    primarykey
    data
    text
    <p>I tried to replace a <code>Fragment</code> in <code>FragmentActivity</code> run-time.</p> <h2>fragment_activity.xml</h2> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent" /&gt; </code></pre> <h2>MyFragmentActivity.java</h2> <pre><code>public class MyFragmentActivity extends SlidingFragmentActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_activity); } // Will be called by AsyncTaskLoader's onLoadFinished. public void selectActiveContent() { // MyFragment's top level is LinearLayout Fragment fragment = new MyFragment(); getSupportFragmentManager().beginTransaction().replace(R.id.content, fragment).commitAllowingStateLoss(); } </code></pre> <p>However, I realize the outcome is not optimized.</p> <p><img src="https://i.stack.imgur.com/pUC87.png" alt="enter image description here"></p> <p>I realize the <code>FrameLayout</code> supplied through my own <code>fragment_activity.xml</code>, is being attached to another parent <code>FrameLayout</code>.</p> <p>Instead of </p> <pre><code>FrameLayout FrameLayout LinearLayout LinearLayout ListView </code></pre> <p>I wish to have</p> <pre><code>FrameLayout LinearLayout LinearLayout ListView </code></pre> <p>May I know how I can achieve so? Is it possible I can have a <code>fragment_activity.xml</code> without a <code>ViewGroup</code> (FrameLayout) ?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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