Fragment Compatibility Animator Sample
Animate compat fragment with Honeycomb Animation API
These new APIs are great, but they are not quite compatible with older devices, thus Google provided a support library to solve this problem.
While building my app, I'm trying to use the compat fragment to support as many devices as possible, meanwhile, I want to take advantage of new set of animation apis to create animation easier.
The FragmentTransaction class has a simple API named
setCustomAnimations() to set the animation while switching fragments. But, sadly, when I tried to use the animator xml file (I mean, using property animation elements like
<objectAnimator> in the animation xml) on Gingerbread emulator (with API level less than 11), the app simply crashed complaining it does not understand the
objectAnimator sh*t, which means you have to give up on the new animation API with compat fragment.
That's why I've built this sample. If you are interested, I've written a blog post explaining how I work this whole thing out.
The green rounded rectange as well as the blue one are two fragments, whose code is extracted from ActionBarSherlock's styled action bar demo. Once I clicked the
android.R.id.home button on actionbar, the fragment starts to flip by changing the
Read the code
If you happen to be interested in this topic, I strongly recommend you to read the code, it's easy and straight forward. When encountered problem, try to refer to my blog post for detailed explanation. If the problem is still there or, even better, you have some advice for me, fell free to contact me, the address is firstname.lastname@example.org
This is only a demo, the code is ugly and unorganized, I plan to build a simple util class to make using animator api for compat fragment even easier, so stay tuned, or star this project for further update.