Die onCreateAnimator
Methode ist ungerade. Der Prototyp ich gesehen habe, ist dies:
public Animator onCreateAnimator(int transit, boolean enter, int nextAnim)
int transit
- Übergangstyp, wie sandrstar über die
boolean enter
- true, wenn 'Eingabe' false sonst
int nextAnim
- Die Ressourcen-ID der Animation, die gerade abgespielt werden soll.
So zum Beispiel, wenn Sie eine Karte Flip versuchten dabei, from the documentation:
// Create and commit a new fragment transaction that adds the fragment for the back of
// the card, uses custom animations, and is part of the fragment manager's back stack.
BackOfCardFragment backFragment = new BackOfCardFragment();
getFragmentManager()
.beginTransaction()
// Replace the default fragment animations with animator resources representing
// rotations when switching to the back of the card, as well as animator
// resources representing rotations when flipping back to the front (e.g. when
// the system Back button is pressed).
.setCustomAnimations(
R.animator.card_flip_right_in, R.animator.card_flip_right_out,
R.animator.card_flip_left_in, R.animator.card_flip_left_out)
// Replace any fragments currently in the container view with a fragment
// representing the next page (indicated by the just-incremented currentPage
// variable).
.replace(R.id.container_view, backFragment)
// Add this transaction to the back stack, allowing users to press Back
// to get to the front of the card.
.addToBackStack(null)
// Commit the transaction.
.commit();
HINWEIS: R.id.container_view in dem obigen Beispiel ist die ID ein Viewgroup, die das bestehende Fragment enthält Sie versuchen zu ersetzen.
Wenn der obige Code ausgeführt wird, wird die onCreateAnimator
Methode aufgerufen, und der nextAnim
Parameter wird eine der vier Animation IDs in die setCustomAnimations()
Funktion, dh R.animator.card_flip_right_in, R.animator.card_flip_right_out weitergegeben werden. .. etc.
Dies scheint zunächst nicht sofort nützlich zu sein, da es keinen Verweis auf das eigentliche Animator-Objekt gibt, an das Sie einen Listener anhängen können.Aber seltsam, können Sie einfach einen anderen Animator aufblasen direkt von der nextAnim
Ressource, und dann bringen die Zuhörer zu dem, was wird, seltsam, alle überschriebene Rückrufe zu den richtigen Zeiten Feuer:
@Override
public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
Animator animator = null;
// In this example, i want to add a listener when the card_flip_right_in animation
// is about to happen.
if (nextAnim == R.animator.card_flip_right_in) {
animator = AnimatorInflater.loadAnimator(getActivity(), nextAnim);
// * Sometimes onCreateAnimator will be called and nextAnim will be 0,
// causing animator to be null.
// * I wanted to add a listener when the fragment was entering -
// your use case may be different.
if (animator != null && enter) {
animator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
// Do something when the card flip animation begins
}
@Override
public void onAnimationEnd(Animator animation) {
// Do something as soon as the card flip animation is over
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
}
}
return animator;
}
Auf diese Weise sollten Sie in der Lage sein, den Fragment Transition-Animatoren Listener hinzuzufügen, als ob Sie sie selbst erstellt hätten.
Scheint, dass diese Ergebnisse der Methodenverwendung eine Idee geben könnten http://grepcode.com/search/usages?type=method&id=repository.grepcode.com%24java%[email protected]%[email protected] 2_r1 @ android% 24app @ Fragment @ onCreateAnimator% 28int% 2Cboolean% 2Cint% 29 & k = u – sandrstar