Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to implement View Shaker in Android

  • Difficulty Level : Hard
  • Last Updated : 23 Feb, 2021

View Shaker is an animation in which, the UI of screen vibrates for a limited period of time. This can be implemented on the whole layout or some particular widget. It is a very common effect that developers use, especially to show incorrect credentials.

View Shaker helps us to animate the widgets. Various effects can be added to it.

  1. Attension
      Flash, Pulse, RubberBand, Shake, Swing, Wobble, Bounce, Tada, StandUp, Wave

  2. Special
      Hinge, RollIn, RollOut, Landing, TakingOff, DropOut

  3. Bounce
      BounceIn, BounceInDown, BounceInLeft, BounceInRight, BounceInUp

  4. Fade
      FadeIn, FadeInUp, FadeInDown, FadeInLeft, FadeInRight
      FadeOut, FadeOutDown, FadeOutLeft, FadeOutRight, FadeOutUp

  5. Flip
      FlipInX, FlipOutX, FlipOutY

  6. Rotate
      RotateIn, RotateInDownLeft, RotateInDownRight, RotateInUpLeft, RotateInUpRight
      RotateOut, RotateOutDownLeft, RotateOutDownRight, RotateOutUpLeft, RotateOutUpRight

  7. Slide
      SlideInLeft, SlideInRight, SlideInUp, SlideInDown
      SlideOutLeft, SlideOutRight, SlideOutUp, SlideOutDown

  8. Zoom
      ZoomIn, ZoomInDown, ZoomInLeft, ZoomInRight, ZoomInUp
      ZoomOut, ZoomOutDown, ZoomOutLeft, ZoomOutRight, ZoomOutUp

In this article we will see an example of adding such a effect in an app.

In this example, a user wants to log into GeeksforGeeks portal. The user enters the wrong password and then clicks on the login button. Then we can animate our view making the app more responsive, using View Shaker.

  1. Add the support Library in build.gradle file and add dependency in the dependencies section. This library has various animations effect described above. It helps in making our application more responsive and dynamic.

    dependencies {
        implementation 'com.daimajia.easing:library:2.0@aar'
        implementation 'com.daimajia.androidanimations:library:2.3@aar'
  2. Now add the following code in the activity_main.xml file. This code add one textview, two edittexts and a button on activity_main.


    <?xml version="1.0" encoding="utf-8"?>
            android:hint="Enter ID"
            android:hint="Enter Password"
            android:text="Log In"/>

  3. Now add the following code in the file. onClickListener is added to Log In button which adds the Shake effect on both the edittext.The different functions like duration sets the duration, repeat set the number of times the effect should be repeated and playOn sets the effect on a particular widget.

    package org.geeksforgeeks.gfgviewshaker;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import com.daimajia.androidanimations
    import com.daimajia.androidanimations
    public class MainActivity
        extends AppCompatActivity {
        Button login;
        EditText id, password;
        protected void onCreate(
            Bundle savedInstanceState)
            login = findViewById(;
            id = findViewById(;
            password = findViewById(;
                new View.OnClickListener() {
                    public void onClick(View v)


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!