FragmentTransaction animations not working

5,992 views
Skip to first unread message

Adil Hussain

unread,
Jan 26, 2012, 5:27:03 AM1/26/12
to Android Compatibility Library for Google Maps - Support
Hi all,

First of, big thanks to those responsible for putting this library
together. Very very useful.

I can't seem to get FragmentTransaction animations to work. I've tried
using the setCustomAnimations(int enter, int exit) method as well as
the setTransition(int transit) method but to no avail. Anyone been
able to get animations to work, or also had problems getting
animations to work?

Regards,
Adil

ps. Some of the animations I tried:

setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
setCustomAnimations(android.R.anim.slide_in_left,
android.R.anim.slide_out_right)

Pete Doyle

unread,
Jan 30, 2012, 3:10:33 PM1/30/12
to android-support-v4...@googlegroups.com
Hi Adil,
Sorry for the delay.  We don't do anything different with regard to animations than the stock compatibility library, so you might ask around elsewhere (StackOverflow, android-developers mailing list, etc).

I've only tried TRANSIT_FRAGMENT_OPEN and have it working well on an original Droid (2.3/Gingerbread).

Here's an excerpt of the exact code I'm using (obviously you'd have to edit a bit for your app):

public final class UIUtils {
... snip ...

public static void replaceFragment(Fragment currentFragment, Fragment newFragment, String tag) throws IllegalStateException {
currentFragment
.getFragmentManager()
.beginTransaction()
.remove( currentFragment )
.replace( android.R.id.content, newFragment, tag )
.addToBackStack( null )
.setTransition( FragmentTransaction.TRANSIT_FRAGMENT_OPEN )
.commit();
}
... snip ...
}

Most of my calls are from other fragments, like this:
UIUtils.replace(this, new OtherFragment(), null);

Thanks,
Pete

Adil Hussain

unread,
Feb 3, 2012, 1:31:31 PM2/3/12
to Android Compatibility Library for Google Maps - Support
Thanks for the response Pete.

I tried TRANSIT_FRAGMENT_OPEN, TRANSIT_FRAGMENT_CLOSE and
TRANSIT_FRAGMENT_FADE again and they do seem to transition a bit
different than when a transition is not set. Very rapid and not very,
well, animated though so gonna try figure custom animations out. I've
read somewhere that the old animation types are no good and I'll need
to define an 'object animator' instead for this so will give that a
try to begin with.

Thanks again. Oh and I've put up a stack overflow question if anyone
does happen to know or comes across any leads for this:
http://stackoverflow.com/questions/9016822/support-library-fragmenttransaction-animations-not-working

Regards,
Adil
> On Thu, Jan 26, 2012 at 2:27 AM, Adil Hussain <a...@thinkincode.co.uk>wrote:
>
>
>
> > Hi all,
>
> > First of, big thanks to those responsible for putting this library
> > together. Very very useful.
>
> > I can't seem to get FragmentTransaction animations to work. I've tried
> > using the setCustomAnimations(int enter, int exit) method as well as
> > the setTransition(int transit) method but to no avail. Anyone been
> > able to get animations to work, or also had problems getting
> > animations to work?
>
> > Regards,
> > Adil
>
> > ps. Some of the animations I tried:
>
> > setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
> > setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
> > setCustomAnimations(android.R.anim.slide_in_left,
> > android.R.anim.slide_out_right)- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages