title: Problem performing LayoutAnimation in RecyclerView when triggered by SwipeRefreshLayout
body: <p>I am trying to perform a custom animation in my RecyclerView using the XML property <code>android:layoutAnimation</code>. </p>
  
  <p>The problem is: When I populate my adapter directly in the activity's <code>onCreate()</code>, the animation triggers normally. However, when I try to populate my recyclerView from the <code>SwipeRefreshLayout.setOnRefreshListener</code> the animation is not triggered correctly. </p>
  
  <p>I have no idea what is wrong.</p>
  
  <h2>Dependencies</h2>
  
  <pre><code>implementation 'androidx.recyclerview:recyclerview:1.0.0'
  implementation 'androidx.cardview:cardview:1.0.0'
  implementation 'com.google.android.material:material:1.1.0-alpha04'
  </code></pre>
  
  <h2>XML files</h2>
  
  <p>Activity XML:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;androidx.recyclerview.widget.RecyclerView
          android:id="@+id/postListRecyclerView"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:clipToPadding="false"
          android:layoutAnimation="@anim/layout_animation_enter_up"
          android:paddingTop="8dp"
          android:paddingBottom="8dp" /&gt;
  </code></pre>
  
  <p>layout_animation_enter_up.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;layoutAnimation
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:animation="@anim/item_animation_enter_up"
      android:animationOrder="normal"
      android:delay="15%" /&gt;
  </code></pre>
  
  <p>item_animation_enter_up.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;set xmlns:android="http://schemas.android.com/apk/res/android"
      android:duration="600"&gt;
  
      &lt;translate
          android:fromYDelta="50%p"
          android:interpolator="@android:anim/decelerate_interpolator"
          android:toYDelta="0" /&gt;
  
      &lt;alpha
          android:fromAlpha="0"
          android:interpolator="@android:anim/decelerate_interpolator"
          android:toAlpha="1" /&gt;
  
  &lt;/set&gt;
  </code></pre>
  
  <h2><a href="https://github.com/phellipealexandre/CoolPosts" rel="nofollow noreferrer">My Code</a> in simplified version</h2>
  
  <p>This code triggers the <em>layout_animation_enter_up</em> animation correctly:</p>
  
  <pre><code>override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_post_list)
  
      val adapter = PostsAdapter()
      postListRecyclerView.adapter = adapter
      val dummyData = Post(1, "Title", "Body", 1, "Name")
      val postList = listOf(dummyData, dummyData, dummyData, dummyData, dummyData, dummyData, dummyData)
  
      adapter.submitList(postList)
  }
  </code></pre>
  
  <p>This code <strong>does not</strong> trigger the <em>layout_animation_enter_up</em> animation:</p>
  
  <pre><code>override fun onCreate(savedInstanceState: Bundle?) {
      postListSwipeRefreshLayout.setOnRefreshListener {
          val adapter = PostsAdapter()
          postListRecyclerView.adapter = adapter
          val dummyData = Post(1, "Title", "Body", 1, "Name")
          val postList = listOf(dummyData, dummyData, dummyData, dummyData, dummyData, dummyData, dummyData)
  
          adapter.submitList(postList)
      }
  }
  </code></pre>
  
  <p>In both code snippets (that are basically the same), I am considering that the RecyclerView is going <strong>from an empty state to a populated state</strong>. Is there any difference on the UI perspective if I populate my adapter inside the <code>setOnRefreshListener</code> callback or inside the <code>onCreate</code>?</p>
  
  <p><strong>Edit</strong>: The snippets above are different from the original codebase just to make the explanation easier. I don't want to know about performance in this question. I would like to know why the animation does not work in the second snippet and works fine in the first snippet.</p>