title: Why does my layout view animate its size before its sibling has changed its size?
body: <p>I have a simple layout with 4 LinearLayout groups each holding a different type of view. What I am trying to do is start off the screen by have the LinearLayouts "collapsed" by turning their child's visibility to View.GONE. On each layout, as well as the layout's parent, I have android:animateLayoutChanges="true" so that when I click on the Layout (which is set to clickable), its child will have its visibility set to View.VISIBLE, thus expanding its parent LinearLayout nicely.</p>
  
  <p>All this works fine when I set its visibility to View.VISIBLE, but when I click it again, I set it back to View.GONE so that the LinearLayout will shrink.</p>
  
  <p>The problem I am facing is that when it shrinks, it seems like the LinearLayout's height gets updated immediately before it has time to start animating, so its siblings below it animate upwards immediately, looking quick bad.</p>
  
  <p>Here is a small animation of what's going on:</p>
  
  <p><img src="https://i.stack.imgur.com/B9f1X.gif" alt="enter image description here"></p>
  
  <p>I can tell that the child (the DatePicker) starts to fade out when I set the visibility to View.GONE.</p>
  
  <p>Here is some code to show how I am approaching this (irrelevant items were left out):</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/layoutMain"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:clipChildren="false"
      tools:context=".QuickAddMain"&gt;
  
      &lt;ScrollView
          android:id="@+id/scrollView"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:clipChildren="false"&gt;
  
          &lt;RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:animateLayoutChanges="true"
              android:clipChildren="false"
              android:orientation="vertical"&gt;
  
          &lt;LinearLayout
                  android:id="@+id/testGroup03"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginBottom="5dp"
                  android:layout_marginLeft="10dp"
                  android:layout_marginRight="10dp"
                  android:layout_marginTop="5dp"
                  android:animateLayoutChanges="true"
                  android:background="@drawable/section_background"
                  android:orientation="vertical"&gt;
  
                  &lt;LinearLayout
                      android:id="@+id/testTitle03Clickable"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:background="?android:selectableItemBackground"
                      android:clickable="true"&gt;
  
                      &lt;TextView
                          android:id="@+id/testTitle03"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_marginBottom="10dp"
                          android:layout_marginLeft="10dp"
                          android:layout_marginTop="5dp"
                          android:text="Test Title 03"
                          android:textAppearance="?android:attr/textAppearanceMedium"
                          android:textStyle="bold" /&gt;
  
                  &lt;/LinearLayout&gt;
  
                  &lt;DatePicker
                      android:id="@+id/datePicker"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center_horizontal"
                      android:calendarViewShown="false"
                      android:datePickerMode="spinner"
                      android:visibility="gone" /&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:id="@+id/testGroup04"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginBottom="70dp"
                  android:layout_marginLeft="10dp"
                  android:layout_marginRight="10dp"
                  android:layout_marginTop="5dp"
                  android:animateLayoutChanges="true"
                  android:background="@drawable/section_background"
                  android:orientation="vertical"
                  android:layout_below="@+id/dateGroup"&gt;
  
                  &lt;LinearLayout
                      android:id="@+id/testTitle04Clickable"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:background="?android:selectableItemBackground"
                      android:clickable="true"&gt;
  
                      &lt;TextView
                          android:id="@+id/testTitle04"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_marginBottom="10dp"
                          android:layout_marginLeft="10dp"
                          android:layout_marginTop="5dp"
                          android:text="Test Title 04"
                          android:textAppearance="?android:attr/textAppearanceMedium"
                          android:textStyle="bold" /&gt;
  
                  &lt;/LinearLayout&gt;
  
                  &lt;TimePicker
                      android:id="@+id/timePicker"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center_horizontal"
                      android:timePickerMode="spinner"
                      android:visibility="gone" /&gt;
              &lt;/LinearLayout&gt;
  
          &lt;/RelativeLayout&gt;
      &lt;/ScrollView&gt;
  </code></pre>
  
  <p>Java:</p>
  
  <pre><code>LayoutTransition layoutTransition;
  
  layoutTransition = dateGroup.getLayoutTransition();
  layoutTransition.enableTransitionType(LayoutTransition.CHANGING);
  
  layoutTransition = timeGroup.getLayoutTransition();
  layoutTransition.enableTransitionType(LayoutTransition.CHANGING);
  </code></pre>
  
  <hr>
  
  <pre><code>    dateActivation = (LinearLayout) findViewById(R.id.dateActivation);
      dateActivation.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if (datePicker.getVisibility() == View.GONE) {
                  datePicker.setVisibility(View.VISIBLE);
              } else {
                  datePicker.setVisibility(View.GONE);
              }
          }
      });
  
      timeActivation = (LinearLayout) findViewById(R.id.timeActivation);
      timeActivation.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if (timePicker.getVisibility() == View.GONE) {
                  timePicker.setVisibility(View.VISIBLE);
              } else {
                  timePicker.setVisibility(View.GONE);
              }
          }
      });
  </code></pre>
  
  <p>Please let me know if I'm missing anything or if anything needs to be clarified. Thanks.</p>