Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Click animation on view

    • 0
    • 5
    • 1
    • 2
    • 0
    • 0
    • 0
    • 0
    • 301
    Comment on it

    Hello Android folks,

    We've been using selectors and xmls whenever we wanted to apply click effect to the views. Here is very simple and short way to achieve the same.

    We can use Android's AnimationUtils class to load the animation on any view.

    Below is the sample code which loads the fade_in animation on views which are being clicked:

     @Override
        public void onClick(View v) {
            v.startAnimation(loadAnimation(this, android.R.anim.fade_in));
            if(v.getId()==R.id.userImage)
            {
    
            }
            else if(v.getId()==R.id.nextButton)
            {
    
            }
        }
    

    Also, import AnimationUtil calss like:

    import static android.view.animation.AnimationUtils.loadAnimation;
    

    It serves the purpose in almost all circumstances and keeps us from writing selectors and xmls for so many views.

    Thanks

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: