I have a GridView of layouts which can be dynamically added or removed to the grid.
In iOS, the native behavior for GridView items is for the other items in the grid to
I've found this resource link quite helpful for dealing with animation for other layout views such as LinearLayout etc.: http://developer.android.com/training/animation/layout.html Hopefully this can help. You can also have a look at https://github.com/nhaarman/ListViewAnimations for inspiration
I think for AdapterViews, the LayoutTransition of ViewGroup won't work. Looking at the source code, ViewGroup ensures the transition animations of other children happen for calls to addView
and removeView
, but the derived AdapterView doesn't use those methods, since it relies on an adapter for supplying views.
Chet Haase's video mentioned above is about animating a single child view of a ListView that is disappearing, rather than animating all other surrounding child views that move to fill in the gap.
And, if I'm understanding it right, the GridLayoutAnimationController is about staggered animations for the children as they fill in (ie first time or a complete relayout of the whole list, starting from empty), rather than animating in-place layout changes of surrounding children after an add or remove. so, do the children appear by fading in or sliding in or spinning in - always one at a time, from first to last.
Finally, a suggested solution: if you don't need an adapter-based view, you could switch to GridLayout or LinearLayout. That's where animateLayoutChanges="true"
will work, and what the 'layout animation' demos always use.
Note LayoutTransition requires minimum api level 11. and GridLayout requires api14.
After you have made any changes to the GridView like .remove() you have to call mGrid.startLayoutAnimation();
The GridView won't do it automatically for you. You have to trigger it manually ;-)
Chet Haase came out with a nice video on how to handle ListView animations properly. The basic concept can be applied to GridViews. You can find the video here.
If you're developing for API 1.0+, you won't be able to use the referenced animation features that the video mentions (such as ViewPropertyAnimator) unless you use NineOldAndroids.