2014-12-03 3 views
0

Сначала она работает плавно, как предполагалось, и заканчивается, но после этого она останавливается на полпути как на устройстве, так и на эмуляторах genymotion. Интересно, что с теми же анимациями он заканчивается и воспроизводится, если я соединяю только 3-5. Я использую Android Studio 1.0 RC2.Анимация не воспроизводится после первой попытки

Соответствующая часть MainActivity

private static final String ANIM = "Animation"; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     Button btn = (Button) findViewById(R.id.button); 

     final ImageView iv = (ImageView) findViewById(R.id.imageV); 
     iv.setVisibility(View.INVISIBLE); 

     final Animation slideUpFromBottom = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_in_bottom); 
     final Animation slideLeft = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_out_left); 
     final Animation slideInFromLeft = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_in_left); 
     final Animation slideOutAtBottom = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_out_bottom); 
     final Animation slideOutAtTop = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_out_top); 
     final Animation slideInFromTop = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_in_top); 
     final Animation slideInFromRight = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_in_right); 
     final Animation slideOutToRight = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_out_right); 

     btn.setOnClickListener(new View.OnClickListener() 
     { 
      @Override 
      public void onClick(View v) 
      { 
       slideUpFromBottom.setAnimationListener(new Animation.AnimationListener() 
       { 
        @Override 
        public void onAnimationStart(Animation animation) 
        { 
         Log.d(ANIM,"Startes slideUpFromBottom"); 
         iv.setVisibility(View.VISIBLE); 
        } 

        @Override 
        public void onAnimationEnd(Animation animation) 
        { 
         Log.d(ANIM, "Finished slideUpFromBottom"); 
         slideLeft.setStartOffset(100); 
         iv.setVisibility(View.INVISIBLE); 
         iv.startAnimation(slideLeft); 
         slideUpFromBottom.reset(); 
        } 

        @Override 
        public void onAnimationRepeat(Animation animation) 
        { 

        } 
       }); 

       slideLeft.setAnimationListener(new Animation.AnimationListener() 
       { 
        @Override 
        public void onAnimationStart(Animation animation) 
        { 
         Log.d(ANIM, "Started slideLeft"); 
         iv.setVisibility(View.VISIBLE); 
        } 

        @Override 
        public void onAnimationEnd(Animation animation) 
        { 
         Log.d(ANIM, "Finished slideLeft"); 
         slideInFromLeft.setStartOffset(100); 
         iv.setVisibility(View.INVISIBLE); 
         iv.startAnimation(slideInFromLeft); 
         slideLeft.reset(); 
        } 

        @Override 
        public void onAnimationRepeat(Animation animation) 
        { 

        } 
       }); 

       slideInFromLeft.setAnimationListener(new Animation.AnimationListener() 
       { 
        @Override 
        public void onAnimationStart(Animation animation) 
        { 
         Log.d(ANIM, "Started slideInFromLeft"); 
         iv.setVisibility(View.VISIBLE); 
        } 

        @Override 
        public void onAnimationEnd(Animation animation) 
        { 
         Log.d(ANIM, "Finished slideInFromLeft"); 
         slideOutAtTop.setStartOffset(100); 
         iv.setVisibility(View.INVISIBLE); 
         iv.startAnimation(slideOutAtTop); 
         slideInFromLeft.reset(); 
        } 

        @Override 
        public void onAnimationRepeat(Animation animation) 
        { 

        } 
       }); 

       slideOutAtTop.setAnimationListener(new Animation.AnimationListener() 
       { 
        @Override 
        public void onAnimationStart(Animation animation) 
        { 
         Log.d(ANIM, "Started slideOutAtTop"); 
         iv.setVisibility(View.VISIBLE); 
        } 

        @Override 
        public void onAnimationEnd(Animation animation) 
        { 
         Log.d(ANIM, "Finished slideOutAtTop"); 
         slideInFromTop.setStartOffset(100); 
         iv.setVisibility(View.INVISIBLE); 
         iv.setAnimation(slideInFromTop); 
         slideOutAtTop.reset(); 
        } 

        @Override 
        public void onAnimationRepeat(Animation animation) 
        { 

        } 
       }); 

       slideInFromTop.setAnimationListener(new Animation.AnimationListener() 
       { 
        @Override 
        public void onAnimationStart(Animation animation) 
        { 
         Log.d(ANIM, "Started slideInFromTop"); 
         iv.setVisibility(View.VISIBLE); 
        } 

        @Override 
        public void onAnimationEnd(Animation animation) 
        { 
         Log.d(ANIM, "Finished slideInFromTop"); 
         slideOutToRight.setStartOffset(100); 
         iv.setVisibility(View.INVISIBLE); 
         iv.setAnimation(slideOutToRight); 
         slideInFromTop.reset(); 
        } 

        @Override 
        public void onAnimationRepeat(Animation animation) 
        { 

        } 
       }); 

       slideOutToRight.setAnimationListener(new Animation.AnimationListener() 
       { 
        @Override 
        public void onAnimationStart(Animation animation) 
        { 
         Log.d(ANIM, "Started slideOutToRight"); 
         iv.setVisibility(View.VISIBLE); 
        } 

        @Override 
        public void onAnimationEnd(Animation animation) 
        { 
         Log.d(ANIM, "Finished slideOutToRight"); 
         slideInFromRight.setStartOffset(100); 
         iv.setVisibility(View.INVISIBLE); 
         iv.setAnimation(slideInFromRight); 
         slideOutToRight.reset(); 
        } 

        @Override 
        public void onAnimationRepeat(Animation animation) 
        { 

        } 
       }); 

       slideInFromRight.setAnimationListener(new Animation.AnimationListener() 
       { 
        @Override 
        public void onAnimationStart(Animation animation) 
        { 
         Log.d(ANIM, "Started slideInFromRight"); 
         iv.setVisibility(View.VISIBLE); 
        } 

        @Override 
        public void onAnimationEnd(Animation animation) 
        { 
         Log.d(ANIM, "Finished slideInFromRight"); 
         slideOutAtBottom.setStartOffset(100); 
         iv.setVisibility(View.INVISIBLE); 
         iv.setAnimation(slideOutAtBottom); 
         slideInFromRight.reset(); 
        } 

        @Override 
        public void onAnimationRepeat(Animation animation) 
        { 

        } 
       }); 

       slideOutAtBottom.setAnimationListener(new Animation.AnimationListener() 
       { 
        @Override 
        public void onAnimationStart(Animation animation) 
        { 
         Log.d(ANIM, "Started slideOutAtBottom"); 
         iv.setVisibility(View.VISIBLE); 
        } 

        @Override 
        public void onAnimationEnd(Animation animation) 
        { 
         Log.d(ANIM, "Finished slideOutAtBottom"); 
         iv.setVisibility(View.INVISIBLE); 
         slideOutAtBottom.reset(); 
        } 

        @Override 
        public void onAnimationRepeat(Animation animation) 
        { 

        } 
       }); 

       iv.startAnimation(slideUpFromBottom); 
      } 
     }); 

    } 

slide_in_bottom.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/accelerate_interpolator" 
    android:shareInterpolator="true"> 

    <translate 
     android:duration="1000" 
     android:fromXDelta="0" 
     android:fromYDelta="150%" 
     android:toXDelta="0" 
     android:toYDelta="0" /> 

</set> 

slide_in_left.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/accelerate_interpolator" 
    android:shareInterpolator="true"> 

    <translate 
     android:fromXDelta="-100%" 
     android:toXDelta="0%" 
     android:fromYDelta="0%" 
     android:toYDelta="0%" 
     android:duration="1000" /> 
</set> 

slide_in_right.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/accelerate_interpolator" 
    android:shareInterpolator="true"> 


    <translate 
     android:fromXDelta="100%" 
     android:toXDelta="0%" 
     android:fromYDelta="0%" 
     android:toYDelta="0%" 
     android:duration="1000" /> 
</set> 

slide_in_top.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/accelerate_interpolator" 
    android:shareInterpolator="true"> 

    <translate 
     android:fromXDelta="0%" 
     android:toXDelta="0%" 
     android:fromYDelta="-150%" 
     android:toYDelta="0%" 
     android:duration="1000"/> 
</set> 

slide_out_bottom.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/accelerate_interpolator" 
    android:shareInterpolator="true"> 

    <translate 
     android:fromXDelta="0%" 
     android:toXDelta="0%" 
     android:fromYDelta="0%" 
     android:toYDelta="150%" 
     android:duration="1000"/> 
</set> 

slide_out_left.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/accelerate_interpolator" 
    android:shareInterpolator="true"> 

    <translate 
     android:fromXDelta="0%" 
     android:toXDelta="-100%" 
     android:fromYDelta="0%" 
     android:toYDelta="0%" 
     android:duration="1000" /> 
</set> 

slide_out_right.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/accelerate_interpolator" 
    android:shareInterpolator="true"> 


    <translate 
     android:fromXDelta="0%" 
     android:toXDelta="100%" 
     android:fromYDelta="0%" 
     android:toYDelta="0%" 
     android:duration="1000" /> 
</set> 

slide_out_top.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/accelerate_interpolator" 
    android:shareInterpolator="true"> 

    <translate 
    android:fromXDelta="0%" 
    android:toXDelta="0%" 
    android:fromYDelta="0%" 
    android:toYDelta="-150%" 
    android:duration="1000"/> 
</set> 

ответ

1

Я предполагаю, что это потому, что вы используете .setAnimation внутри некоторых из ваших onAnimationEnd.

Если вы хотите использовать .setAnimation, вам может потребоваться сначала позвонить .setStartTime.

или просто используйте .startAnimation для всех анимаций.

+0

Замена всех 'setAnimation'' .startAnimation' работал :) thx – Miklosflame

Смежные вопросы