Reputation: 12463
I have an animation that I use to make an ImageView
bounce when it is clicked.
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/bounce_interpolator">
<scale
android:duration="500"
android:fromXScale="1.5"
android:fromYScale="1.5"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
and I apply it like this.
view.startAnimation(
AnimationUtils.loadAnimation(view.getContext(), R.anim.bounce));
It works just fine, but the problem is that the animation affects not only the image drawn inside the ImageView
but its background as well. When the animation occurs, its background enlarges and exceeds the view bounds, overlapping other views beside it. Is there a way to apply the animation only to the Drawable
inside the ImageView
, so that it does not affect the view background?
(P.S: If this question has already been answered, then please do mark it as a duplicate. I've searched but haven't been able to find an answer that matches what I am looking for.)
Upvotes: 0
Views: 31
Reputation: 489
I'm not sure if that can be done. But as a workaround, you can place one ImageView
over another. Set the background to the ImageView
below and set the background for the ImageView
above as transparent. Now set the Drawable
to the ImageView
on top and animate that ImageView
.
Upvotes: 1