SikhWarrior
SikhWarrior

Reputation: 1087

Android wait until activity is ready for animations

I have an issue with activities loading and then beginning any sort of animation. Usually by the time the activity is loaded up the animation is already half way complete or completely choppy.

And this is for mostly all cases: progress spinner animation, recyclerview list animations and so on so forth.

Is there anyway I can smooth out the animations when an activity is loaded? Maybe delay everything until the UI is ready to handle the animations and list load?

Here is my scenario.

  1. User clicks button to open activity, activity loads fragment
  2. Fragment onActivityCreated starts progress bar spinner and begins retrieving saved list items from shared preferences, or async network call if not cached (list is never more than 10 items, very small objects of ~8 strings).
  3. RecyclerView is loaded with adapter and adapter animates items by sliding/fading them in.

Both animations, the progress bar and slide/fade in are already half way complete by the time it is visible, or become very choppy. Is there any way to make this a bit smoother?

Here is the list as requested: enter image description here

Thanks.

Edit: Ill add, that on this activity, the fade in animation is non existent, and the slide in is about halfway complete when it loads.

Upvotes: 3

Views: 1960

Answers (1)

DriesOeyen
DriesOeyen

Reputation: 493

As of API level 21, you can implement the Activity#onEnterAnimationComplete() callback and use that to start your animations. Unfortunately, it seems like there's no AppCompat equivalent at this point.

When I faced this issue, I decided to implement the onEnterAnimationComplete() callback on sufficiently high API levels, while on lower levels I simply fall back to starting animations in onCreate().

Upvotes: 3

Related Questions