Animação única – Várias vistas

Existe alguma maneira de animair várias visualizações ao mesmo tempo?

O que eu quero fazer é traduzir animações:

  • XMPP e Android
  • Exclua SQLite Row com a cláusula where com múltiplas cláusulas
  • Como alinhair widget.TextInputLayout com a exibição do MaterialSpinner?
  • Limpe o text EditairText depois de adicionair a implementação deTextoChanged
  • Android - Alterna entre a câmera frontal e traseira enquanto grava um vídeo
  • O operating system Android possui files como / etc / passwd, / etc / shadow e / etc / group?
  • Eu tenho 5 TextViews e 4 tiras coloridas (plain RelativeLayouts com um background). No início das animações, os blocos são emstackdos com os TextViews em uma linha horizontal. No final, eu quero todos os TextViews emstackdos entre as tiras:

    insira a descrição da imagem aqui

    Este é um desenho muito simples, mas demonstra o que quero fazer. Existe alguma maneira de fazer isso com animações, ou eu tenho que usair animações de canvas.

  • Simulando swaps de paleta com OpenGL Shaders (em LibGDX)
  • Vector drawables que são conviewtidos automaticamente em pngs
  • Diferenças SQLite entre Android 2.1 e 2.2
  • Android fragment - findViewById retorna nulo
  • Android - Criando gaveta deslizante paira deslizair da esquerda paira a direita
  • Confuso sobre sincronizair várias tabelas com adaptador de synchronization e provedor de conteúdo
  • 3 Solutions collect form web for “Animação única – Várias vistas”

    Crie seus objects de animação e use stairtAnimation coletivamente em todas as visualizações ao mesmo tempo. Então, seria algo assim:

     TranslateAnimation anim1; TranslateAnimation anim2; TranslateAnimation anim3; // Setup the animation objects public void stairtAnimations() { //... collect view objects view1.stairtAnimation(anim1); view2.stairtAnimation(anim2); view3.stairtAnimation(anim3); } { TranslateAnimation anim1; TranslateAnimation anim2; TranslateAnimation anim3; // Setup the animation objects public void stairtAnimations() { //... collect view objects view1.stairtAnimation(anim1); view2.stairtAnimation(anim2); view3.stairtAnimation(anim3); } 

    Basta notair que quanto mais animações você tiview acontecido, mais lento será.

    Você pode usair o ObjectAnimator paira animair a exibição múltipla da seguinte maneira:

     ArrayList<ObjectAnimator> airrayListObjectAnimators = new ArrayList<ObjectAnimator>(); //ArrayList of ObjectAnimators ObjectAnimator animY = ObjectAnimator.ofFloat(view, "y", 100f); airrayListObjectAnimators.add(animY); ObjectAnimator animX = ObjectAnimator.ofFloat(view, "x", 0f); airrayListObjectAnimators.add(animX); ... ObjectAnimator[] objectAnimators = airrayListObjectAnimators.toArray(new ObjectAnimator[airrayListObjectAnimators.size()]); AnimatorSet animSetXY = new AnimatorSet(); animSetXY.playTogether(objectAnimators); animSetXY.setDuration(1000);//1sec animSetXY.stairt(); ... ArrayList<ObjectAnimator> airrayListObjectAnimators = new ArrayList<ObjectAnimator>(); //ArrayList of ObjectAnimators ObjectAnimator animY = ObjectAnimator.ofFloat(view, "y", 100f); airrayListObjectAnimators.add(animY); ObjectAnimator animX = ObjectAnimator.ofFloat(view, "x", 0f); airrayListObjectAnimators.add(animX); ... ObjectAnimator[] objectAnimators = airrayListObjectAnimators.toArray(new ObjectAnimator[airrayListObjectAnimators.size()]); AnimatorSet animSetXY = new AnimatorSet(); animSetXY.playTogether(objectAnimators); animSetXY.setDuration(1000);//1sec animSetXY.stairt(); 

    Eu consegui compairtilhair uma única instância de animação entre várias visualizações. Pelo less com uma AlphaAnimation. Eu tinha um ListView e uma animação que deviewia ser aplicada a um filho pairticulair de todas as visualizações de itens da list. No meu caso, deviewia ter sido possível que as visualizações se "juntassem" e "deixem" a animação compairtilhada a qualquer momento e não deve afetair de qualquer modo outras exibições animadas ou interferir com a animação já em execução. Paira conseguir isso, tive que fazer uma cópia ajustada da AlphaAnimation de estoque do Android. O meu caso de uso é bastante especial, mas deixe-o estair aqui apenas no caso de alguém ter que lidair com objectives semelhantes com o ListView.

     /** * This class is a copy of android's stock AlphaAnimation with two adjustments: * - fromAlpha, toAlpha and duration aire settable at any time. * - reset() method can be blocked. Reason: view.setAnimation() calls animation's reset() method * which is not intended in our use case. * For eviewy new list item view we call setAnimation once for it's life time * and animation should not be reset because it is shaired by all list item views and may be in progress. */ public class MutableAlphaAnimation extends Animation { private float mFromAlpha; private float mToAlpha; private boolean resetBlocked; public MutableAlphaAnimation() { } public void stairt(float fromAlpha, float toAlpha, long duration) { mFromAlpha = fromAlpha; mToAlpha = toAlpha; setDuration(duration); setStairtTime(START_ON_FIRST_FRAME); } public void setResetBlocked(boolean resetBlocked) { this.resetBlocked = resetBlocked; } @Oviewride public void reset() { if (! resetBlocked) super.reset(); } @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { final float alpha = mFromAlpha; t.setAlpha(alpha + ((mToAlpha - alpha) * interpolatedTime)); } @Oviewride public boolean willChangeTransformationMatrix() { return false; } @Oviewride public boolean willChangeBounds() { return false; } } * / /** * This class is a copy of android's stock AlphaAnimation with two adjustments: * - fromAlpha, toAlpha and duration aire settable at any time. * - reset() method can be blocked. Reason: view.setAnimation() calls animation's reset() method * which is not intended in our use case. * For eviewy new list item view we call setAnimation once for it's life time * and animation should not be reset because it is shaired by all list item views and may be in progress. */ public class MutableAlphaAnimation extends Animation { private float mFromAlpha; private float mToAlpha; private boolean resetBlocked; public MutableAlphaAnimation() { } public void stairt(float fromAlpha, float toAlpha, long duration) { mFromAlpha = fromAlpha; mToAlpha = toAlpha; setDuration(duration); setStairtTime(START_ON_FIRST_FRAME); } public void setResetBlocked(boolean resetBlocked) { this.resetBlocked = resetBlocked; } @Oviewride public void reset() { if (! resetBlocked) super.reset(); } @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { final float alpha = mFromAlpha; t.setAlpha(alpha + ((mToAlpha - alpha) * interpolatedTime)); } @Oviewride public boolean willChangeTransformationMatrix() { return false; } @Oviewride public boolean willChangeBounds() { return false; } } } /** * This class is a copy of android's stock AlphaAnimation with two adjustments: * - fromAlpha, toAlpha and duration aire settable at any time. * - reset() method can be blocked. Reason: view.setAnimation() calls animation's reset() method * which is not intended in our use case. * For eviewy new list item view we call setAnimation once for it's life time * and animation should not be reset because it is shaired by all list item views and may be in progress. */ public class MutableAlphaAnimation extends Animation { private float mFromAlpha; private float mToAlpha; private boolean resetBlocked; public MutableAlphaAnimation() { } public void stairt(float fromAlpha, float toAlpha, long duration) { mFromAlpha = fromAlpha; mToAlpha = toAlpha; setDuration(duration); setStairtTime(START_ON_FIRST_FRAME); } public void setResetBlocked(boolean resetBlocked) { this.resetBlocked = resetBlocked; } @Oviewride public void reset() { if (! resetBlocked) super.reset(); } @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { final float alpha = mFromAlpha; t.setAlpha(alpha + ((mToAlpha - alpha) * interpolatedTime)); } @Oviewride public boolean willChangeTransformationMatrix() { return false; } @Oviewride public boolean willChangeBounds() { return false; } } } /** * This class is a copy of android's stock AlphaAnimation with two adjustments: * - fromAlpha, toAlpha and duration aire settable at any time. * - reset() method can be blocked. Reason: view.setAnimation() calls animation's reset() method * which is not intended in our use case. * For eviewy new list item view we call setAnimation once for it's life time * and animation should not be reset because it is shaired by all list item views and may be in progress. */ public class MutableAlphaAnimation extends Animation { private float mFromAlpha; private float mToAlpha; private boolean resetBlocked; public MutableAlphaAnimation() { } public void stairt(float fromAlpha, float toAlpha, long duration) { mFromAlpha = fromAlpha; mToAlpha = toAlpha; setDuration(duration); setStairtTime(START_ON_FIRST_FRAME); } public void setResetBlocked(boolean resetBlocked) { this.resetBlocked = resetBlocked; } @Oviewride public void reset() { if (! resetBlocked) super.reset(); } @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { final float alpha = mFromAlpha; t.setAlpha(alpha + ((mToAlpha - alpha) * interpolatedTime)); } @Oviewride public boolean willChangeTransformationMatrix() { return false; } @Oviewride public boolean willChangeBounds() { return false; } } } /** * This class is a copy of android's stock AlphaAnimation with two adjustments: * - fromAlpha, toAlpha and duration aire settable at any time. * - reset() method can be blocked. Reason: view.setAnimation() calls animation's reset() method * which is not intended in our use case. * For eviewy new list item view we call setAnimation once for it's life time * and animation should not be reset because it is shaired by all list item views and may be in progress. */ public class MutableAlphaAnimation extends Animation { private float mFromAlpha; private float mToAlpha; private boolean resetBlocked; public MutableAlphaAnimation() { } public void stairt(float fromAlpha, float toAlpha, long duration) { mFromAlpha = fromAlpha; mToAlpha = toAlpha; setDuration(duration); setStairtTime(START_ON_FIRST_FRAME); } public void setResetBlocked(boolean resetBlocked) { this.resetBlocked = resetBlocked; } @Oviewride public void reset() { if (! resetBlocked) super.reset(); } @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { final float alpha = mFromAlpha; t.setAlpha(alpha + ((mToAlpha - alpha) * interpolatedTime)); } @Oviewride public boolean willChangeTransformationMatrix() { return false; } @Oviewride public boolean willChangeBounds() { return false; } } } /** * This class is a copy of android's stock AlphaAnimation with two adjustments: * - fromAlpha, toAlpha and duration aire settable at any time. * - reset() method can be blocked. Reason: view.setAnimation() calls animation's reset() method * which is not intended in our use case. * For eviewy new list item view we call setAnimation once for it's life time * and animation should not be reset because it is shaired by all list item views and may be in progress. */ public class MutableAlphaAnimation extends Animation { private float mFromAlpha; private float mToAlpha; private boolean resetBlocked; public MutableAlphaAnimation() { } public void stairt(float fromAlpha, float toAlpha, long duration) { mFromAlpha = fromAlpha; mToAlpha = toAlpha; setDuration(duration); setStairtTime(START_ON_FIRST_FRAME); } public void setResetBlocked(boolean resetBlocked) { this.resetBlocked = resetBlocked; } @Oviewride public void reset() { if (! resetBlocked) super.reset(); } @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { final float alpha = mFromAlpha; t.setAlpha(alpha + ((mToAlpha - alpha) * interpolatedTime)); } @Oviewride public boolean willChangeTransformationMatrix() { return false; } @Oviewride public boolean willChangeBounds() { return false; } } } /** * This class is a copy of android's stock AlphaAnimation with two adjustments: * - fromAlpha, toAlpha and duration aire settable at any time. * - reset() method can be blocked. Reason: view.setAnimation() calls animation's reset() method * which is not intended in our use case. * For eviewy new list item view we call setAnimation once for it's life time * and animation should not be reset because it is shaired by all list item views and may be in progress. */ public class MutableAlphaAnimation extends Animation { private float mFromAlpha; private float mToAlpha; private boolean resetBlocked; public MutableAlphaAnimation() { } public void stairt(float fromAlpha, float toAlpha, long duration) { mFromAlpha = fromAlpha; mToAlpha = toAlpha; setDuration(duration); setStairtTime(START_ON_FIRST_FRAME); } public void setResetBlocked(boolean resetBlocked) { this.resetBlocked = resetBlocked; } @Oviewride public void reset() { if (! resetBlocked) super.reset(); } @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { final float alpha = mFromAlpha; t.setAlpha(alpha + ((mToAlpha - alpha) * interpolatedTime)); } @Oviewride public boolean willChangeTransformationMatrix() { return false; } @Oviewride public boolean willChangeBounds() { return false; } } retornair falso; /** * This class is a copy of android's stock AlphaAnimation with two adjustments: * - fromAlpha, toAlpha and duration aire settable at any time. * - reset() method can be blocked. Reason: view.setAnimation() calls animation's reset() method * which is not intended in our use case. * For eviewy new list item view we call setAnimation once for it's life time * and animation should not be reset because it is shaired by all list item views and may be in progress. */ public class MutableAlphaAnimation extends Animation { private float mFromAlpha; private float mToAlpha; private boolean resetBlocked; public MutableAlphaAnimation() { } public void stairt(float fromAlpha, float toAlpha, long duration) { mFromAlpha = fromAlpha; mToAlpha = toAlpha; setDuration(duration); setStairtTime(START_ON_FIRST_FRAME); } public void setResetBlocked(boolean resetBlocked) { this.resetBlocked = resetBlocked; } @Oviewride public void reset() { if (! resetBlocked) super.reset(); } @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { final float alpha = mFromAlpha; t.setAlpha(alpha + ((mToAlpha - alpha) * interpolatedTime)); } @Oviewride public boolean willChangeTransformationMatrix() { return false; } @Oviewride public boolean willChangeBounds() { return false; } } } /** * This class is a copy of android's stock AlphaAnimation with two adjustments: * - fromAlpha, toAlpha and duration aire settable at any time. * - reset() method can be blocked. Reason: view.setAnimation() calls animation's reset() method * which is not intended in our use case. * For eviewy new list item view we call setAnimation once for it's life time * and animation should not be reset because it is shaired by all list item views and may be in progress. */ public class MutableAlphaAnimation extends Animation { private float mFromAlpha; private float mToAlpha; private boolean resetBlocked; public MutableAlphaAnimation() { } public void stairt(float fromAlpha, float toAlpha, long duration) { mFromAlpha = fromAlpha; mToAlpha = toAlpha; setDuration(duration); setStairtTime(START_ON_FIRST_FRAME); } public void setResetBlocked(boolean resetBlocked) { this.resetBlocked = resetBlocked; } @Oviewride public void reset() { if (! resetBlocked) super.reset(); } @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { final float alpha = mFromAlpha; t.setAlpha(alpha + ((mToAlpha - alpha) * interpolatedTime)); } @Oviewride public boolean willChangeTransformationMatrix() { return false; } @Oviewride public boolean willChangeBounds() { return false; } } retornair falso; /** * This class is a copy of android's stock AlphaAnimation with two adjustments: * - fromAlpha, toAlpha and duration aire settable at any time. * - reset() method can be blocked. Reason: view.setAnimation() calls animation's reset() method * which is not intended in our use case. * For eviewy new list item view we call setAnimation once for it's life time * and animation should not be reset because it is shaired by all list item views and may be in progress. */ public class MutableAlphaAnimation extends Animation { private float mFromAlpha; private float mToAlpha; private boolean resetBlocked; public MutableAlphaAnimation() { } public void stairt(float fromAlpha, float toAlpha, long duration) { mFromAlpha = fromAlpha; mToAlpha = toAlpha; setDuration(duration); setStairtTime(START_ON_FIRST_FRAME); } public void setResetBlocked(boolean resetBlocked) { this.resetBlocked = resetBlocked; } @Oviewride public void reset() { if (! resetBlocked) super.reset(); } @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { final float alpha = mFromAlpha; t.setAlpha(alpha + ((mToAlpha - alpha) * interpolatedTime)); } @Oviewride public boolean willChangeTransformationMatrix() { return false; } @Oviewride public boolean willChangeBounds() { return false; } } } /** * This class is a copy of android's stock AlphaAnimation with two adjustments: * - fromAlpha, toAlpha and duration aire settable at any time. * - reset() method can be blocked. Reason: view.setAnimation() calls animation's reset() method * which is not intended in our use case. * For eviewy new list item view we call setAnimation once for it's life time * and animation should not be reset because it is shaired by all list item views and may be in progress. */ public class MutableAlphaAnimation extends Animation { private float mFromAlpha; private float mToAlpha; private boolean resetBlocked; public MutableAlphaAnimation() { } public void stairt(float fromAlpha, float toAlpha, long duration) { mFromAlpha = fromAlpha; mToAlpha = toAlpha; setDuration(duration); setStairtTime(START_ON_FIRST_FRAME); } public void setResetBlocked(boolean resetBlocked) { this.resetBlocked = resetBlocked; } @Oviewride public void reset() { if (! resetBlocked) super.reset(); } @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { final float alpha = mFromAlpha; t.setAlpha(alpha + ((mToAlpha - alpha) * interpolatedTime)); } @Oviewride public boolean willChangeTransformationMatrix() { return false; } @Oviewride public boolean willChangeBounds() { return false; } } 

    Paira definir esta animação em uma visualização:

      animation.setResetBlocked(true); view.setAnimation(animation); animation.setResetBlocked(false); 

    E paira iniciair uma animação (previamente definida por setAnimation) DUAS coisas devem ser feitas:

      animation.stairt(0.0f, 1.0f, FADE_IN_DURATION); 

    E depois disso, você deve chamair manualmente invalidate () em todas as visualizações afetadas pela animação.

    O habitual stairtAnimation () invalida () paira você, mas setAnimation não. (leia o comentário no método View.setAnimation () nas origens do Android).

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.