Question

Je ne parviens pas à utiliser ou de comprendre comment éclater FragmentTransactions hors de la pile arrière poignées la coutume animations. Plus précisément, je pense à appeler l'animation « out », mais il ne semble pas.

J'ai une méthode simple pour gérer une opération de fragment (FragmentTransaction) où ajouter un fragment et appliquer une coutume transition de sorte qu'il sera fade-in / fade-out. Je suis également d'ajouter ceci à la pile de retour de sorte que l'utilisateur peut annuler la transaction avec le bouton précédent, essentiellement à l'état de navigation avant que le fragment était ajouté.

protected void changeFragment() { 
    FragmentTransaction ft = fm.beginTransaction(); 
    ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out); 
    ft.add(R.id.fragment_container, new TestFragment()); 
    ft.addToBackStack(null); 
    ft.commit(); 
} 

Tout fonctionne très bien en mouvement vers l'avant, mais lorsque l'utilisateur clique sur le bouton retour, les animations de transition ne pas inverser. Ce que j'attendais était que lorsque le fragment obtenu enlevé, il utiliserait le Fade Out animation. Au contraire, il semble sortir (sans animation) puis le récipient semble disparaître. Je ne suis pas sûr que ce soit exactement ce que qui se passe, mais le fragment est certainement pas fane dehors.

Mon application utilise la bibliothèque de compatibilité pour ajouter le support fragment, mais je suppose que cela est applicable à Honeycomb (Android-11) ainsi. Est-ce que quelqu'un sait si je suis juste en train de faire quelque chose de mal ici ou si je suis juste trop attendre? Idéalement, je voudrais animer la fragments de façon similaire à la façon dont Gmail (sur la Xoom) fait en ce qui concerne aller de l'avant en cliquant sur un message, puis de nouveau en utilisant le dos bouton. De préférence, ne pas avoir à remplacer le bouton de retour fonctionnalité et suivre mon propre état de fragment que je pouvais ont plusieurs « opérations » que je voudrais revenir sur et je suis pas un ventilateur de roues de ré-inventer.

a également demandé au Groupe Développeurs Android: http://groups.google.com/group / android-développeurs / browse_thread / fil / 1136a3a70fa0b6e9

Était-ce utile?

La solution

The bug was fixed in the 3.2 release with the addition of the following new api:

http://developer.android.com/reference/android/app/FragmentTransaction.html#setCustomAnimations(int, int, int, int)

It's to be noted that it has not yet been back-ported to the compatibility library (as mentioned in the bug report).

Autres conseils

I use this:

ft.setCustomAnimations(R.anim.slide_in, R.anim.hyperspace_out, R.anim.hyperspace_in, R.anim.slide_out);

and the transitions work in reverse when the back button is presses.

It's a bug, look at bug report 15623. One of the Android project members commented that the fix was too late for release 3.1 but it should make it into the next release.

The same member goes on to say that...

The problem is that the same animations are run on a pop operation as were run to put the fragments in their current places. For example, in the sliding example above, on a forward operation (pushing the old fragment onto the stack and moving the new fragment into view), we slide the old fragment out from the center to the left and slide the new fragment in from the right to the center. When the stack is popped, these same animations are run: the most recent fragment is animated 'out' by sliding it in from the right to the center (after which it disappears, since it's being removed). The old fragment is popped off the stack and animated from teh center to the left ... right off the screen.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top