zoom in and zoom out animation in android

73,478

Solution 1

You can use this method after running the command to start your new activity,

startActivity(intent);
overridePendingTransition(animation_in_goes_here,animation_out_goes_here);

Then you may replace your animations above, replacing the animation_in_goes_here with the animation resource you need for the activity that you have newly started and replacing animation_out_goes_here with the animation resource for the activity that you are leaving from. This will give you the switching effects.

zoom_in.xml

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

zoom_out.xml

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

Hope this helped to answer your question.

Solution 2

Zoom In

<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fromXScale="0"
    android:fromYScale="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="0.5"
    android:toYScale="0.5">

</scale>

Zoom Out

<scale xmlns:android="http://schemas.android.com/apk/res/android"

    android:duration="1000"
    android:fromXScale="2.1"
    android:fromYScale="2.1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:startOffset="3000"
    android:toXScale="0"
    android:toYScale="0">

</scale>

Solution 3

I think you have to do as follow

  • Set "in" and "out" animations
  • Create folder res/anim
  • Put animation descriptions into res/anim folder

    object.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.zoom_enter)); object.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.zoom_exit));

You can use android sdk sample animations supplied by google under Apache 2.0 licence

Or refer this which uses scaling based zooming which is easier than the former

http://developer.android.com/training/animation/zoom.html

Share:
73,478

Related videos on Youtube

jagdish
Author by

jagdish

Updated on July 09, 2022

Comments

  • jagdish
    jagdish almost 2 years

    I have code of normally zoom in and zoom out animation between two activities, but I want something different. I have five buttons on my first activity if I click on first button then zoom in would be starts from position of first button only instead of zooming from centre. Please help me.

    EDIT : Zoom should start from the button I clicked as a centre.

    • kabuto178
      kabuto178 over 10 years
      Your question is not quite clear, you want to zoom in from the center of the layout or, is it that your animation is not working correctly?
    • jagdish
      jagdish over 10 years
      I have five button when I click on any button it will be expand and starting next activity.
    • kabuto178
      kabuto178 over 10 years
      You do not want to start a new activity?
    • jagdish
      jagdish over 10 years
      I want start new activity also. But animation would be like expanding
  • jagdish
    jagdish over 10 years
    thnax...but animation is not proper :(
  • kabuto178
    kabuto178 over 10 years
    How so what seems to be the problem?
  • Shubham A.
    Shubham A. almost 9 years
    This animation is not proper. No transition is happening with the activity I am leaving. Activity I am switching to, first zooms in and then switches back to normal. Nothing happens with the activity I am leaving. Is there any dependency I am loosing? This answer got 8 thumbs as of now so must be correct in a context.
  • Maulik Dadhaniya
    Maulik Dadhaniya almost 8 years
    create zoom.xml this is use for zoom out and zoom in
  • Black mamba
    Black mamba almost 4 years
    how to make both effect in one ?
  • Black mamba
    Black mamba almost 4 years
    how to make both effect in one ?