title: Does LinearLayout with visibility GONE consume zero resources?
body: <p>I was thinking about how to implement an <em>ImageView</em> that shows an image and while I'm refreshing its content with a new image it shows a "Loading..." text with a circular <em>ProgressBar</em> on the right, so I've written the code attached below.. Is this the correct way to implement what I want? Does the <em>LinearLayout</em> with <em>TextView</em> and <em>ProgressBar</em> consume zero resources when it's visibility is set to GONE? Does the <em>ProgressBar</em> itself consume zero resources (I'm thinking about the progress looping circle animation) when itself or it's parent layout's visibility is set to GONE? If I'd set it to INVISIBLE it should consume a bit of resources due to Layout management, but it still should not consume resources for animating the progress circle, right?</p>
  
  <p><strong>EDIT</strong>: when I've said "does it consumes resources" above, I meant CPU resources, since it obviously consumes a bit of memory resources since I do not release the view when I simply set its visibility to <em>GONE</em>. I've added this comment after the first comment and the first answer.</p>
  
  <p>I hope the code  below is correct, in case some other newbie like me is wondering how to implement the same thing.</p>
  
  <p>Follows the code and an image showing the result on an emulator:</p>
  
  <p><img src="https://i.stack.imgur.com/jxcQH.png" alt="enter image description here"></p>
  
  <p><strong>main.xml</strong>
  
      
      </p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;FrameLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
  
          &lt;ImageView
              android:id="@+id/image_view1"
              android:src="@drawable/fish"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:scaleType="centerCrop"
              android:contentDescription="image view 1" /&gt;
  
  
         &lt;LinearLayout
             android:id="@+id/layout_progress"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:layout_gravity="center_vertical"
             android:background="@drawable/filled_rectangle"
             android:gravity="center_vertical|center_horizontal"
             android:orientation="horizontal"
             android:visibility="gone" &gt;
  
             &lt;TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:gravity="fill_horizontal"
                 android:text="Loading..."  
                 android:textSize="30sp" 
                 android:layout_gravity="center_vertical"/&gt;
  
                 &lt;!-- style="@android:style/Widget.ProgressBar.Small" --&gt; 
             &lt;ProgressBar
                 android:id="@+id/progress_bar1"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_gravity="center_vertical"
                 android:indeterminateOnly="true"/&gt;
  
         &lt;/LinearLayout&gt;
     &lt;/FrameLayout&gt;
  
     &lt;Button
         android:id="@+id/refresh_image"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="center_horizontal"
         android:onClick="onClick" 
         android:text="@string/refresh_image"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>drawables/filled_rectangle.xml</strong>
  </p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;shape xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="rectangle"&gt;
      &lt;solid android:color="#80000000"/&gt;
  &lt;/shape&gt;
  </code></pre>
  
  <p><strong>TestFrameLayoutActivity.java</strong>
  </p>
  
  <pre class="lang-java prettyprint-override"><code>public class TestFrameLayoutActivity extends Activity {
      private int progressVisible;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          LinearLayout layout = (LinearLayout) findViewById(R.id.layout_progress);
          progressVisible = (layout.getVisibility() == View.VISIBLE)?1:0;
      }
  
      public void onClick (View view) {
          progressVisible = 1 - progressVisible;
          LinearLayout layout = (LinearLayout) findViewById(R.id.layout_progress);
          ImageView img = (ImageView) findViewById(R.id.image_view1);
  
          if (progressVisible == 1) {
              layout.setVisibility(ProgressBar.VISIBLE);
          } else {
              layout.setVisibility(ProgressBar.GONE);
          }
      }
  }
  </code></pre>