具有多个图像淡入淡出动画的android imageview

标签 android android-layout android-animation

第一次来这里提问... 我希望有人能帮助我....

我想为多个图像设置动画,这些图像以淡入淡出 的方式进行动画处理。我能够为一个 imageview 制作动画,但我需要的是一旦第一个 imageview 淡出,第二个 imageview 必须淡入等等......

应用程序打开后它应该循环。谢谢

这是我在 java onCreate() 中调用动画的方式,

   final ImageView image = (ImageView)findViewById(R.id.bsc);
   final Animation animationFadeIn = AnimationUtils.loadAnimation(this,     R.anim.fadein);
   image.startAnimation(animationFadeIn);
   final Animation animationFadeOut = AnimationUtils.loadAnimation(this, R.anim.fadeout);
image.startAnimation(animationFadeOut);

淡入.xml

      <?xml version="1.0" encoding="utf-8"?>
     <set xmlns:android="http://schemas.android.com/apk/res/android"
       android:interpolator="@android:anim/linear_interpolator">
      <alpha 
         android:fromAlpha="0.1" 
         android:toAlpha="1.0" 
         android:duration="2000" 
         />
    </set>  

淡出.xml

     <?xml version="1.0" encoding="utf-8"?>
 <set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">
<alpha 
    android:fromAlpha="1.0" 
    android:toAlpha="0.1" 
    android:duration="2000" 
    />
 </set>

最佳答案

尝试使用 AnimationListener。

final ImageView image = (ImageView)findViewById(R.id.bsc);
final Animation animationFadeIn = AnimationUtils.loadAnimation(this, R.anim.fadein);
final Animation animationFadeOut = AnimationUtils.loadAnimation(this, R.anim.fadeout);

AnimationListener animListener = new AnimationListener(){

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            }

        @Override
        public void onAnimationEnd(Animation animation) {
            image.setImageResource(R.drawable.hsc);
            image.startAnimation(animationFadeIn);
        }
    };
image.startAnimation(animationFadeOut);
animationFadeOut.setAnimationListener(animListener);

如果你想循环,那么还要在 animationFadeIn 上放置另一个监听器。这将再次启动 animationFadeOut。从数组中选取图像并显示。

关于具有多个图像淡入淡出动画的android imageview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16909437/

相关文章:

android - 如何为alertdialog换行内容制作自定义布局

android - Android 中 gui 元素的动态数量?

android - 将 Fresco 与 StaggeredGridLayoutManager 结合使用

android - Activity 跳转开始时的动画

java - 不幸的是,在Android中打开gmail应用程序的 Intent 停止了

android - java.lang.BootstrapMethodError:初始化Retrofit时,调用站点#4 Bootstrap 方法发生异常

android - 在 Kindle Fire 上检查 PDF Intent 没有返回任何内容?

java - Android webView在fragment中显示空白页面

android - 如何为 Android 制作动画视频

android - TranslateAnimation 如何在 Android 上运行?