2012-09-13 14 views
13

Me gusta la animación que se produce al desplazarme por publicaciones en la aplicación de Google+, pero no puedo entender cómo lo logran.¿Cómo logra Google las publicaciones animadas en su aplicación G +?

¿Qué técnicas se emplean para animar las publicaciones a medida que aparecen? No estoy buscando la animación en sí, solo cómo aplicaría cualquier animación a una lista de elementos desplazables.

Gracias.

+0

hace [esto] (http://stackoverflow.com/questions/6850490/how-does-scrolling-work-in- the-google-android-app) ¿ayuda? – cosmincalistru

+0

@cosmincalistru Esa es una pregunta diferente, entonces no. – Glitch

Respuesta

10

Después de algunas pruebas, creo que obtuve algo similar al trabajo;

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    final LinearLayout list = new LinearLayout(this); 
    list.setOrientation(LinearLayout.VERTICAL); 

    ScrollView scrollView = new ScrollView(this) { 
     Rect mRect = new Rect(); 

     @Override 
     public void onLayout(boolean changed, int l, int t, int r, int b) { 
      super.onLayout(changed, l, t, r, b); 

      for (int i = 0; i < list.getChildCount(); ++i) { 
       View v = list.getChildAt(i); 

       // Tag initially visible Views as 'true'. 
       mRect.set(l, t, r, b); 
       v.setTag(getChildVisibleRect(v, mRect, null));     
      } 
     } 

     @Override 
     public void onScrollChanged(int l, int t, int oldl, int oldt) { 
      super.onScrollChanged(l, t, oldl, oldt); 

      for (int i = 0; i < list.getChildCount(); ++i) { 
       View v = list.getChildAt(i); 
       mRect.set(getLeft(), getTop(), getRight(), getBottom()); 

       // If tag == 'false' and View is visible we know that 
       // View became visible during this scroll event. 
       if ((Boolean) v.getTag() == false 
         && getChildVisibleRect(v, mRect, null)) { 
        AlphaAnimation anim = new AlphaAnimation(0, 1); 
        anim.setDuration(1000); 
        v.startAnimation(anim); 
        v.setTag(true); 
       } 
      } 
     } 
    }; 
    scrollView.addView(list); 

    for (int i = 0; i < 20; ++i) { 
     TextView tv = new TextView(this); 
     tv.setText("Test"); 
     tv.setTextSize(72); 
     tv.setTextColor(Color.WHITE); 
     tv.setBackgroundColor(Color.GRAY); 
     list.addView(tv); 
    } 

    setContentView(scrollView); 
} 

desplazarse por la lista debe desencadenar la animación alfa vez nuevos TextView s se hacen visibles.

+0

¡Gracias, parece que funciona! Tuve que reemplazar 'v.setAnimation (anim)' con '' v.startAnimation (anim) 'sin embargo, de lo contrario no se animaría. – Glitch

+0

¿Qué tan eficiente es eso? Hay una razón por la cual Android especifica que usemos un ListView para desplazarnos a través de una lista de elementos – jonney

Cuestiones relacionadas