Sudarshan
Sudarshan

Reputation: 1036

Zoom out & fade in of an imageView at the same time

I'm making a splash screen that contains an ImageView.

I want to fade in and zoom out the ImageView at the same time (simultaneously). I used the xml below for the zoom out animation:

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

And the Java code below:

Animation zoomout = AnimationUtils.loadAnimation(this, R.anim.zoomout);
imageView.setAnimation(zoomout);

And for the fade in animation I used the Java code below:

    Animation fadeIn = new AlphaAnimation(1, 0);  
    fadeIn.setInterpolator(new AccelerateInterpolator());
    fadeIn.setStartOffset(500);
    fadeIn.setDuration(1000); 
    imageView.setAnimation(fadeIn);

But I'm failing to do this at the same time. How to use the two effects simultaneously on the ImageView?

Upvotes: 4

Views: 4480

Answers (1)

Arlind Hajredinaj
Arlind Hajredinaj

Reputation: 8519

Add the following to your xml zoomout:

 <?xml version="1.0" encoding="utf-8"?>
 <set xmlns:android="http://schemas.android.com/apk/res/android"
     android:fillAfter="true"
     android:fillEnabled="true">

    <alpha
        android:duration="1000"
        android:fromAlpha="1.0"
        android:startOffset="1"
        android:toAlpha="0.0"/>

    <scale
        android:duration="1000"
        android:fromXScale="1"
        android:fromYScale="1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale=".5"
        android:toYScale=".5"/>
</set>

And remove the java code for the fade in animation

Animation fadeIn = new AlphaAnimation(1, 0);  
fadeIn.setInterpolator(new AccelerateInterpolator());
fadeIn.setStartOffset(500);
fadeIn.setDuration(1000); 
imageView.setAnimation(fadeIn);

Here is a reference http://thegeekyland.blogspot.com/2015/12/android-animations-explained.html

Upvotes: 5

Related Questions