2012-01-26 15 views
10

Estoy usando la biblioteca de soporte de android-support-v4-googlemaps de Peter Doyle para implementar una actividad que usa tanto fragmentos como Google Maps, y parece que no puede hacer funcionar las animaciones de FragmentTransaction. Intenté utilizar el método setCustomAnimations(int enter, int exit) y el método setTransition(int transit), pero fue en vano. ¿Alguien ha podido hacer que las animaciones funcionen, o también ha tenido problemas para hacer funcionar las animaciones?Biblioteca de soporte: las animaciones FragmentTransaction no funcionan

Algunas de las animaciones que he intentado:

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) 
+1

Creí que lo tenía trabajando en Galaxy S2 pero no en los demás. Volveré a actualizarlo cuando llegue a trabajar mañana por la mañana. – RobGThai

+1

Marque esta pregunta. La respuesta aceptada me ayudó. http://stackoverflow.com/questions/7718111/android-fragment-standard-transition-not-animating – Sababado

Respuesta

1

has necesitado FragmentTransaction.remove() y luego FragmentTransaction.add(), en lugar de FragmentTransaction.replace()? He visto en otros hilos que las quejas sobre replace() no funcionan como se esperaba.

No he utilizado la biblioteca android-support-v4-googlemaps, pero puedo confirmar el código de abajo trabaja con android-support-v4.jar:

FragmentTransaction tx = getSupportFragmentManager().beginTransaction(); 
tx.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right); 
tx.replace(R.id.fragment_container, new Fragment2()); 
tx.addToBackStack(null); 
tx.commit(); 
+0

Gracias por la respuesta Andres. Desafortunadamente no pude hacer funcionar las animaciones (excepto 'setTransition (FragmentTransaction.TRANSIT_FRAGMENT_OPEN)' y 'setTransition (FragmentTransaction.TRANSIT_FRAGMENT_CLOSE)' pero encontré otros problemas con esto) así que eliminé las llamadas al método de animación/transición. –

+0

Usar .add() es una mejor solución que el uso de.replace(). Un buen ejemplo es el uso de .replace() en el soporte v27.0.0 con setCustomAnimations, la aplicación simplemente falla cuando el fragmento se elimina de la pila. Para mí, la solución es usar .add(), pero la transacción en animación se pierde cuando @AdilHussain dijo – Pelanes

11

Debe llamar FragmentTransaction. setCustomAnimations primero y luego llame al FragmentTransaction. reemplazar método como este:

 FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); 
     ft.setCustomAnimations(R.anim.fade_out,R.anim.fade_in); 
     ft.replace(R.id.fragmentDetails, detailsFrag); 
+1

OMG !! ¡No puedo creer que sea tan estúpido! me llevó horas! –

0

tratar de hacer una instantánea de su mapa de Google:

private void snapShot() { 
    SnapshotReadyCallback callback = new SnapshotReadyCallback() { 
     Bitmap bitmap; 

     @Override 
     public void onSnapshotReady(Bitmap snapshot) { 
      // TODO Auto-generated method stub 
      bitmap = snapshot; 
      try { 
       FileOutputStream out = new FileOutputStream(getActivity() 
         .getFilesDir() + "/MapSnapshot.png"); 
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); 
      } catch (Exception e) { 
        e.printStackTrace(); 
      } 
     } 
    }; 

    map.snapshot(callback); 

} 

El hacer un nuevo fragmento que tiene solamente una imagen del mapa. Cargue este nuevo fragmento con replace y luego realice la transición en el fragmento que desea reemplazar: final SnapShotFragment snapFrag = new SnapShotFragment(); FragmentTransaction transaction = getFragmentManager() .beginTransaction();

     transaction.replace(MapFragment.this.getId(), 
           snapFrag); 
         transaction.addToBackStack(null); 
         transaction.commit(); 
         getFragmentManager().executePendingTransactions(); 
         final boolean roi = isInROI; 

         WayPointDetailActivity waypointFrag = new WayPointDetailActivity(); 
         waypointFrag.setWayPointId(wp.getId()); 
         waypointFrag.setInRoi(roi); 
         transaction = getFragmentManager() 
           .beginTransaction(); 

         transaction.setCustomAnimations(R.anim.enter, 
           R.anim.exit); 

         transaction.replace(snapFrag.getId(), waypointFrag); 
         transaction.addToBackStack(null); 
         transaction.commit(); 
Cuestiones relacionadas