Android Animation: Click ImageView Icon Pulse (scale enlarge and reset with opacity change)

Jun 21, 2019

Create res/anim/activate.xml

  • Enlarge the icon by 25%, then recover to original size.
  • Change opacity from 0.5 to 1.
<set xmlns:android="http://schemas.android.com/apk/res/android"     android:shareInterpolator="false">    <scale        android:duration="500"        android:fromXScale="1"        android:fromYScale="1"        android:pivotX="50%"        android:pivotY="50%"        android:toXScale="1.25"        android:toYScale="1.25"/>    <scale        android:duration="500"        android:fromXScale="1.25"        android:fromYScale="1.25"        android:pivotX="50%"        android:pivotY="50%"        android:startOffset="500"        android:toXScale="1"        android:toYScale="1"/>    <alpha android:fromAlpha="0.5"           android:toAlpha="1.0"           android:duration="1000"           android:interpolator="@android:anim/accelerate_interpolator"        /></set>

Code

imageView.startAnimation(AnimationUtils.loadAnimation(context, R.anim.activate))

Layout

<LinearLayout
    android:background="@android:color/white"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="8dp"
    android:clipToPadding="false"
    >

    <ImageButton
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/ic_add_block_24dp"
        android:padding="4dp"
        />
</LinearLayout>

NOTE: Parent layout use android:clipToPadding="false" to avoid the enlarged animation being cover/clipped by white padding.

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.