Animating all items in Animation-list

有些话、适合烂在心里 提交于 2019-12-04 05:26:20

问题


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();
}}

回答1:


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



来源:https://stackoverflow.com/questions/14297003/animating-all-items-in-animation-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!