Android shrink and grow sequential animation

I want to make a sequential animation in which two buttons shrink until they disappear and then they grow again to their original size. When I run it the buttons simply disappear without any animations

<?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);

Answers


The following is a grow/shrink animation that works (endlessly). Setting the animation repeatcount wont work of course, but you can add a counter yourself to stop it.

    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);

    viewToAnimate.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)
        {
            viewToAnimate.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)
        {
            viewToAnimate.setAnimation(growAnim);
            growAnim.start();
        }
    });     

use android:repeatMode="reverse" android:repeatCount="infinite" then it will repeat infinite time i am using it in my tween animation its working


        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();
        }
    });

Use the following code, this is the working code. copy this shrink_grow.xml in anim folder.

<?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>

in the code:

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

val scaleDown = ObjectAnimator.ofPropertyValuesHolder(
    view,
    PropertyValuesHolder.ofFloat("scaleX", 0.5f),
    PropertyValuesHolder.ofFloat("scaleY", 0.5f)
)
scaleDown.duration = 2000
scaleDown.repeatMode = ValueAnimator.REVERSE
scaleDown.repeatCount = ValueAnimator.INFINITE
scaleDown.start()

Demo


Need Your Help

Cordova install on Linux

ubuntu cordova sencha-touch-2 command-line-interface xubuntu

Does anyone know how to install Cordova on Ubuntu/xUbuntu?