How can I achieve shake/wobble animation in android programmatically. There is a AndroidViewAnimations library available through which we can get the effect. But I don't want to use any library for this purpose as it tends to increase the apk size.
The code present in the AndroidViewAnimations for shake animation is as follows:
public class ShakeAnimator extends BaseViewAnimator {
@Override
public void prepare(View target) {
getAnimatorAgent().playTogether(
ObjectAnimator.ofFloat(target, "translationX", 0, 25, -25, 25, -25,15, -15, 6, -6, 0)
);
}
}
Can annyone tell me how can I achieve this without any libraries.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken button to show shake animation for image view.
let's say that mView
is the view you want to animate:
ObjectAnimator
.ofFloat(mView, "translationX", 0, 25, -25, 25, -25,15, -15, 6, -6, 0)
.setDuration(duration)
.start();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With