Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animating all items in Animation-list

I have a list of images(around 10) in my "image_list.xml" under "animation-list" specified with "item". And I have made one "fade_in.xml" file for fade in effect of the imgaes. The code works fine without errors.

The only problem I have is that the fade in effect appears in the first image but not in the other items of the image_list. Please tell me a way to make this possible so that all the images have fade in effect when they appear.My code is:

image_list.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
        android:oneshot="false">
<item android:drawable="@drawable/sample1"
    android:duration="2000"/>
<item android:drawable="@drawable/sample2"
    android:duration="2000"/>
<item android:drawable="@drawable/sample3"
    android:duration="2000"/>
<item android:drawable="@drawable/sample4"
    android:duration="2000"/>
. . .
</animation-list>

ImagesActivity.java

   public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    ImageView img_change = (ImageView) findViewById(R.id.images);
    Animation animationFadeIn = AnimationUtils.loadAnimation(this, R.anim.fade_in);
    img_change.setBackgroundResource(R.drawable.image_list);
    AnimationDrawable splashAnimation = (AnimationDrawable) img_change.getBackground();
    if(hasFocus) {
        img_change.setAnimation(animationFadeIn);
        splashAnimation.start();
}}
like image 306
Ankur Sharma Avatar asked Jan 27 '26 04:01

Ankur Sharma


1 Answers

Add enter and exit fade duration before start AnimationDrawable

AnimationDrawable splashAnimation = ((AnimationDrawable) iv.getBackground());

splashAnimation .setEnterFadeDuration(500);
splashAnimation .setExitFadeDuration(500);

animDrawable.start();

It Works for me.

Happy Coding

like image 109
Sachin Shelke Avatar answered Feb 01 '26 06:02

Sachin Shelke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!