2013-03-28 4 views
3

두 개의 단추가 사라질 때까지 축소 된 다음 다시 원래 크기로 늘어나는 연속 애니메이션을 만들고 싶습니다. 나는 그것을 버튼을 실행하면 단순히 어떤 애니메이션안드로이드 애니메이션 축소 및 성장

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

    <scale 
     android:fromXScale="1" 
     android:toXScale="0" 
     android:fromYScale="1" 
     android:toYScale="0" 
     android:duration="400" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     /> 

    <scale 
     android:startOffset="700" 
     android:fromXScale="0" 
     android:toXScale="1" 
     android:fromYScale="0" 
     android:toYScale="1" 
     android:duration="400" 
     android:pivotX="50%" 
     android:pivotY="50%" 
    /> 

</set> 

Animation sgAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.shrink_grow); 
btPrimary.startAnimation(sgAnimation); 
btSecondary.startAnimation(sgAnimation); 
+0

? 버튼이 축소됩니까? – Axarydax

+0

예, 두 애니메이션이 모두 개별적으로 작동합니다. – JoeyCK

답변

10

다음 없이 사라지는 것은 성장한다는/(끝없이) 동작 애니메이션을 축소합니다. 애니메이션 반복 횟수를 설정하는 것은 당연하지만 카운터를 직접 추가하여 중지 할 수 있습니다.

은 (BTW, "L"은 애니메이션을 적용 할보기이다)

final ScaleAnimation growAnim = new ScaleAnimation(1.0f, 1.15f, 1.0f, 1.15f); 
    final ScaleAnimation shrinkAnim = new ScaleAnimation(1.15f, 1.0f, 1.15f, 1.0f); 

    growAnim.setDuration(2000); 
    shrinkAnim.setDuration(2000); 

    l.setAnimation(growAnim); 
    growAnim.start(); 

    growAnim.setAnimationListener(new AnimationListener() 
    { 
     @Override 
     public void onAnimationStart(Animation animation){} 

     @Override 
     public void onAnimationRepeat(Animation animation){} 

     @Override 
     public void onAnimationEnd(Animation animation) 
     { 
      l.setAnimation(shrinkAnim); 
      shrinkAnim.start(); 
     } 
    }); 
    shrinkAnim.setAnimationListener(new AnimationListener() 
    { 
     @Override 
     public void onAnimationStart(Animation animation){} 

     @Override 
     public void onAnimationRepeat(Animation animation){} 

     @Override 
     public void onAnimationEnd(Animation animation) 
     { 
      l.setAnimation(growAnim); 
      growAnim.start(); 
     } 
    });  
3

사용 안드로이드 : repeatMode = 안드로이드 "반전"반복 횟수 다음 = "무한"내가 사용하고 무한한 시간을 반복 할 것이다 그것은 내 트윈 애니메이션에서 작동합니다.

+0

반복이 문제가되지 않았습니다. 그는 그들을 순차적으로 운영하는 방법을 묻습니다. – RichieHH

0

다음 코드를 사용하면 작업 코드입니다. 이 shrink_grow.xml을 anim 폴더에 복사하십시오. 코드에서

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:fillAfter="false" 
android:fillBefore="false" 
android:shareInterpolator="true" > 

<scale 
    android:duration="1000" 
    android:fillAfter="true" 
    android:fillBefore="false" 
    android:fillEnabled="true" 
    android:fromXScale="1.0" 
    android:fromYScale="1.0" 
    android:toXScale="0.0" 
    android:toYScale="0.0" /> 
<scale 
    android:duration="1000" 
    android:fillAfter="true" 
    android:fillBefore="false" 
    android:fillEnabled="true" 
    android:fromXScale="0.0" 
    android:fromYScale="0.0" 
    android:startOffset="1000" 
    android:toXScale="1.0" 
    android:toYScale="1.0" /> 

</set> 

:

두 번째`scale` 애니메이션을 떠날 때 발생하는
Animation sgAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.shrink_grow); 
btPrimary.startAnimation(sgAnimation); 
btSecondary.startAnimation(sgAnimation); 
+0

애니메이션이 순차적으로 작동하는 이유에 대한 설명과 설명은 어떻습니까? – RichieHH

+1

나는 질문에 게시 된 코드를 가지고 놀았고 약간의 변경을했는데 차이점을 볼 수있는 차이점은 1. 차이점은 fromXScale 등에서 float 값을 사용하는 것입니다. 2. fillAfter fillBefore 값. 나는 그것이 왜 작동하지 않고 왜 작동하는지에 대한 정확한 이유를 모른다. – raju

1
 final ScaleAnimation growAnim = new ScaleAnimation(1.0f, 1.5f, 1.0f, 1.5f, Animation.RELATIVE_TO_SELF, 0.5F, Animation.RELATIVE_TO_SELF, 0.5F); 
    final ScaleAnimation shrinkAnim = new ScaleAnimation(1.5f, 1.0f, 1.5f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5F, Animation.RELATIVE_TO_SELF, 0.5F); 

    growAnim.setDuration(2000); 
    shrinkAnim.setDuration(2000); 

    view.setAnimation(growAnim); 
    growAnim.start(); 

    growAnim.setAnimationListener(new Animation.AnimationListener() { 
     @Override 
     public void onAnimationStart(Animation animation) { 
     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 
     } 

     @Override 
     public void onAnimationEnd(Animation animation) { 
      view.setAnimation(shrinkAnim); 
      shrinkAnim.start(); 
     } 
    }); 
    shrinkAnim.setAnimationListener(new Animation.AnimationListener() { 
     @Override 
     public void onAnimationStart(Animation animation) { 
     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 
     } 

     @Override 
     public void onAnimationEnd(Animation animation) { 
      view.setAnimation(growAnim); 
      growAnim.start(); 
     } 
    }); 
관련 문제