Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • ZoomIn and ZoomOut Animation

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 332
    Comment on it

    Animation is generally used to make user interface more attractive and pleasant.
    In android, we can  have the animation from many ways.

    We call a static function loadAnimation() of the class AnimationUtils. to perform animation in android.

    Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.myanimation);


    Here is the example to achieve zooming animation :-

    Step 1:-  Create anim folder under under res directory, and place given two anim xml files there.

    (a) zoom_in.xml
    Here, we have set the different attributes to show the effects

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:fillAfter="true">
        <scale xmlns:android="http://schemas.android.com/apk/res/android"
            android:duration="1000"
            android:fromXScale="1"
            android:fromYScale="1"
            android:pivotX="50%"
            android:pivotY="50%"
            android:repeatCount="infinite"
            android:repeatMode="reverse"
            android:toXScale="1.5"
            android:toYScale="1.5"></scale>
    </set>
    
    
    

    (b) zoom_out.xml
     

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:fillAfter="true">
        <scale xmlns:android="http://schemas.android.com/apk/res/android"
            android:duration="1000"
            android:fromXScale="1"
            android:fromYScale="1"
            android:pivotX="50%"
            android:pivotY="50%"
            android:repeatCount="infinite"
            android:repeatMode="reverse"
            android:toXScale="0.5"
            android:toYScale="0.5"></scale>
    </set>
    

     

    Step:-2 Declare and initialize the necessary variable and views

    private ImageView mImageView;
    private Animation animZoomIn,animZoomOut;
    animZoomIn=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.zoom_in);
    animZoomOut=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.zoom_out);

     

    Step :-3 Include given functions in your activity, and call them in your desired listners:-

    (a) function to show animation effects

    private void showZoomEffect(Animation  animType) {
       mImageView.startAnimation(animType);
    }

     

    (b) function to remove animation effect
    Here, animType is the animation (animZoomIn/animZoomOut) according to your requirement

    private void removeZoomEffect(Animation animType){
    mImageView.clearAnimation();
    }

     

 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: