Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the interpolator for android animations in Java

This seems very simple: I'm trying to set the interpolator to be used for an animation in my App. I need to set this in the Java code, not the XML (It will change according to various things).

From the android website, I've found setInterpolator()

However, I'm not sure how to use this.

I've tried just feeding in the interpolar name (ie. BounceIterpolator), but this did nothing.

I tried R.anim.BounceIterpolator, but Intellisense said anim cannot be resolved or is not a field.

So how can I set the interpolator from the Java?

like image 453
ACarter Avatar asked Feb 16 '12 13:02

ACarter


People also ask

What is animation Interpolator Android?

An interpolator defines the rate of change of an animation. This allows the basic animation effects (alpha, scale, translate, rotate) to be accelerated, decelerated, repeated, etc.

What is Tweened animation in Android?

Tween Animation takes some parameters such as start value , end value, size , time duration , rotation angle e.t.c and perform the required animation on that object. It can be applied to any type of object. So in order to use this , android has provided us a class called Animation.

What is pivotX and pivotY in Android?

The pivotX and pivotY is the central point of the animation. So for example if you want to do Zoom In animation you can use this <? xml version="1.0" encoding="utf-8"?> <

In which folder animation will be stored?

You can find the anim folder by navigating to the app > res > anim. Then go to the anim > right-click > New > Animation Resource File as shown in the below image.


2 Answers

setInterpolator(new BounceInterpolator()); 
like image 58
Reuben Scratton Avatar answered Oct 03 '22 04:10

Reuben Scratton


anim.setInterpolator(context, android.R.anim.bounce_interpolator); 
like image 43
Zsolt Safrany Avatar answered Oct 03 '22 02:10

Zsolt Safrany