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.