动画动画列表中的所有项目

Ank*_*rma 1 android android-image android-animation android-layout android-imageview

我在"image_list.xml"下的"dynamic-list"下面有一个图像列表(大约10个),用"item"指定.我已经制作了一个"fade_in.xml"文件,用于淡化imgaes的效果.代码工作正常,没有错误.

我唯一的问题是淡入效果出现在第一张图片中,但不出现在image_list的其他项目中.请告诉我一种使这种方式成为可能的方法,以便所有图像在出现时都有效.我的代码是:

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>
Run Code Online (Sandbox Code Playgroud)

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();
}}
Run Code Online (Sandbox Code Playgroud)

Sac*_*lke 8

在启动AnimationDrawable之前添加进入和退出淡入淡出持续时间

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

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

animDrawable.start();
Run Code Online (Sandbox Code Playgroud)

这个对我有用.

快乐的编码