Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Animating changes to GridView content
    text
    copied!<p>I have a GridView of layouts which can be dynamically added or removed to the grid.</p> <p>In iOS, the native behavior for GridView items is for the other items in the grid to slide into the place of the removed item, or slide to make room when a new item is added.</p> <p>However on Android the behavior is just for the changes to instantly pop in on the screen. I tried adding custom animations to each getView() call using some tricks in the GridView's adapter, but that ended up causing some problems seen here:</p> <p><a href="https://stackoverflow.com/questions/15845527/android-gridview-loading-the-0-indexed-item-in-a-later-indexs-slot-when-data-se">Android GridView loading the 0 indexed item in a later index&#39;s slot when data set changes</a></p> <p>I tried having the individual views control the animation instead of the getView() method of the adapter, but the end result was identical.</p> <p>I also tried using a GridLayoutAnimationController, like this:</p> <pre><code>Animation animation = AnimationUtils.loadAnimation(mActivity, R.anim.grid_item_fadein); GridLayoutAnimationController controller = new GridLayoutAnimationController(animation, .2f, .2f); mGrid.setLayoutAnimation(controller); </code></pre> <p>This works on the initial load of all GridView content, but any changes to that content just instantly pop in like it does by default.</p> <p>I feel like this is a pretty simple feature, and there should be an easier way to do it. The best I've seen from searching online is <a href="https://github.com/mrKlar/PagedDragDropGrid" rel="nofollow noreferrer">a library</a> which animates GridView items that swap places in the grid, but that isn't what I'm looking for (in that same library, when you remove an item from the Grid via deletion the same instant effect that I'm trying to avoid occurs).</p> <p>A common answer on SO I've also seen is "Look at the APIDemos, there are tons of examples." But as far as I can see, there are actually no examples for animating GridView content changes.</p> <p>Any help is appreciated, thanks.</p>
 

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