android– 动画淡入淡出

android– 动画淡入淡出,第1张

概述使用此代码我只有淡入淡出,我正在寻找如何添加淡出.我添加了另一个名为“fadeout”的xml,但我无法将其集成到我的代码中.ImageViewimageView=(ImageView)findViewById(R.id.imageView);AnimationfadeInAnimation=AnimationUtils.loadAnimation(this,R.anim.fadein);imag

使用此代码我只有淡入淡出,我正在寻找如何添加淡出.我添加了另一个名为“fadeout”的xml,但我无法将其集成到我的代码中.

ImageVIEw imageVIEw = (ImageVIEw)findVIEwByID(R.ID.imageVIEw);Animation fadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fadein);imageVIEw.startAnimation(fadeInAnimation);button1.setonClickListener(new VIEw.OnClickListener() {    public voID onClick(VIEw v) {        imageVIEw.startAnimation(fadeInAnimation);    }}

fadein.xml

<?xml version="1.0" enCoding="UTF-8"?>  <set xmlns:androID="http://schemas.androID.com/apk/res/androID">    <Alpha androID:fromAlpha="0.0" androID:toAlpha="1.0"      androID:interpolator="@androID:anim/accelerate_interpolator"    androID:duration="Your Duration(in milisecond)"    androID:repeatCount="infinite"/> </set>

解决方法:

这是我的解决方案.它使用AnimatorSet. AnimationSet库太麻烦了,无法工作.这提供了淡入和淡出之间的无缝和无限过渡.

public static voID setAlphaAnimation(VIEw v) {    ObjectAnimator fadeOut = ObjectAnimator.offloat(v, "Alpha",  1f, .3f);    fadeOut.setDuration(2000);    ObjectAnimator fadeIn = ObjectAnimator.offloat(v, "Alpha", .3f, 1f);    fadeIn.setDuration(2000);    final AnimatorSet mAnimationSet = new AnimatorSet();    mAnimationSet.play(fadeIn).after(fadeOut);    mAnimationSet.addListener(new AnimatorListenerAdapter() {        @OverrIDe        public voID onAnimationEnd(Animator animation) {            super.onAnimationEnd(animation);            mAnimationSet.start();        }    });    mAnimationSet.start();}
总结

以上是内存溢出为你收集整理的android – 动画淡入淡出全部内容,希望文章能够帮你解决android – 动画淡入淡出所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1098743.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存