title: Android: RelativeLayout background drawable disappears
body: <p>I have an xml layout for a Fragment (android.support.v4.app.Fragment). When this Fragment is added for the first time, the background drawable displays fine. But when this Fragment is replaced with another Fragment, then later replaced back in again (by creating a new instance and using FragmentTransaction.replace()), the background drawable disappears (<em>but not in all cases</em>, see below). Here is the layout xml for the Fragment:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
      &lt;include layout="@layout/footer_photos" /&gt;
      &lt;RelativeLayout
          android:id="@+id/pageLayout"
          android:background="@drawable/body_background2"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_above="@id/footer"&gt;
          &lt;ImageView
              android:id="@+id/page"
              android:layout_height="500dp"
              android:layout_width="400dp"
              android:layout_centerInParent="true"
              android:background="#FFF" /&gt;
      &lt;/RelativeLayout&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>The background drawable in question is in the RelativeLayout with the id "pageLayout". </p>
  
  <p>Possible clues:</p>
  
  <ul>
  <li>When I remove the ImageView in there, the background drawable shows up fine.</li>
  <li>The other Fragments have similar layout xmls (with the same background drawable), but without ImageViews inside of them, and they work fine.</li>
  <li>One of these Fragments has a WebView and buttons inside of it, and this one's background shows up fine.</li>
  <li>After replacing the "WebView Fragment" with the Fragment in question, the background shows up fine (!?).</li>
  </ul>
  
  <p>EDIT: The same issue consistently occurs if an image is loaded into the ImageView then a dialog-themed activity is launched on top of it, then finished. My solution below fixes both cases.</p>