29

I'm trying to create a Infinite pulsing effect in a ImageView. But how is it possible to keep the offset?

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<scale
    android:duration="700"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="0.5"
    android:toYScale="0.5"/>
<scale
    android:duration="700"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:startOffset="700"
    android:toXScale="2"
    android:toYScale="2"/>
</set>
Barett
  • 5,826
  • 6
  • 51
  • 55
Skyrisu
  • 373
  • 1
  • 5
  • 14

3 Answers3

105

This will make your (Image)View pulsate up to 1.2 its size and back, repeatedly.

ImageView iv = (ImageView) findViewById(R.id.my_imageview);

ObjectAnimator scaleDown = ObjectAnimator.ofPropertyValuesHolder(
                    iv,
                    PropertyValuesHolder.ofFloat("scaleX", 1.2f),
                    PropertyValuesHolder.ofFloat("scaleY", 1.2f));
scaleDown.setDuration(310);

scaleDown.setRepeatCount(ObjectAnimator.INFINITE);
scaleDown.setRepeatMode(ObjectAnimator.REVERSE);

scaleDown.start();
Tim
  • 41,901
  • 18
  • 127
  • 145
A. Adam
  • 3,094
  • 1
  • 26
  • 25
0

You can set startOffset values for each animations in your set.

Mus
  • 1,860
  • 2
  • 16
  • 19
0

If you want to create infinite animation, the best way would be to create custom View and in onDraw create your animation. For example: How to animate a path on canvas - android

Actually you can do animation with SurfaceView too.

Community
  • 1
  • 1
QArea
  • 4,955
  • 1
  • 12
  • 22