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 slide into the place of the removed item, or slide to make room when a new item is added.
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:
Android GridView loading the 0 indexed item in a later index's slot when data set changes
I tried having the individual views control the animation instead of the getView() method of the adapter, but the end result was identical.
I also tried using a GridLayoutAnimationController, like this:
Animation animation = AnimationUtils.loadAnimation(mActivity, R.anim.grid_item_fadein); GridLayoutAnimationController controller = new GridLayoutAnimationController(animation, .2f, .2f); mGrid.setLayoutAnimation(controller);
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.
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 library 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).
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.
Any help is appreciated, thanks.
Android Transition Framework can be used for three main things: Animate activity layout content when transitioning from one activity to another. Animate shared elements (Hero views) in transitions between activities. Animate view changes within same activity.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With