Reputation: 2129
I would like to have an image "bump" (or change its size) according to music. I don't need the music detect side, I just need a way to resize the image dymaically and according to an animation. What is the best way to do this?
Upvotes: 0
Views: 47
Reputation: 1871
If you're using at least API 11 and want to animate it smoothly, you can use an ObjectAnimator
to animate various changes to the properties of a View
. For example:
ObjectAnimator oa = ObjectAnimator.ofFloat(myView, View.SCALE_X, 1.0, 1.25);
oa.setDuration(25); //how long the animation lasts in ms, probably short for your purposes
oa.start();
This will scale the X size of the view myView
from the default (1.0) to slightly larger (1.25). You will then need to do the same for the SCALE_Y
property. Note that you will probably want to keep track of the current scale value so that your next animations look nice. For example:
float currentScale = 1.0;
...
void scaleMyView(float newScale) {
ObjectAnimator oa = ObjectAnimator.ofFloat(myView, View.SCALE_X, currentScale, newScale);
oa.setDuration(25);
oa.start();
currentScale = newScale;
}
See also the documentation on ObjectAnimators
if you need more info. Hope this helps!
Upvotes: 1
Reputation: 6010
There is greate animation library for Android.
https://github.com/daimajia/AndroidViewAnimations
https://github.com/2359media/EasyAndroidAnimations
Upvotes: 1
Reputation:
Every View
has setScaleX
and setScaleY
methods. I believe you can use it for this. As far as syncing it to the music, that depends on the way you're playing it.
Upvotes: 1