Skip to content Skip to sidebar Skip to footer

Android: Applying An Animation To A View Creates Runtimeexception

I am setting an animation on my view from following the ApiDemo example (see layout_grid_fade.html):

Solution 1:

UPD: Not every xml in res/anim folder declares an animation. Some of them might declare Animators or LayoutAnimationControllers. Those are not Animations, thus they can't be loaded with the loadAnimation() call.

--

It looks like the gridLayoutAnimation tag describes not a particular basic animation type but rather a GridLayoutAnimationController. So it can be loaded directly with AnimationUtils.loadAnimation() but rather should be set to a ViewGroup (a layout) throuh layoutAnimation property. If you still want to obtain the AnimationController instance in code, use AnimationUtils.loadLayoutAnimation() method:

LayoutAnimationControllerlayoutAnimation= AnimationUtils.loadLayoutAnimation(ViewModel.this, R.anim.layout_grid_fade)

But you hardly can use the layoutAnimation in the way you're doing in your example. I found this article quite useful for understanding the layout animations.

Post a Comment for "Android: Applying An Animation To A View Creates Runtimeexception"