Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 845
JoeyCK Avatar asked Mar 28 '13 15:03

JoeyCK


2 Answers

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

like image 119
Linh Avatar answered Sep 28 '22 07:09

Linh


Add this in xml in anim folder.

    <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true"
    android:interpolator="@android:anim/linear_interpolator">
    <scale
        android:duration="1000"
        android:fromXScale="1"
        android:fromYScale="1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1.15"
        android:toYScale="1.15"
        android:repeatCount="infinite"
        android:repeatMode="reverse"/>
</set>
like image 35
Max Droid Avatar answered Sep 28 '22 08:09

Max Droid