android开发分享Android的阿尔法animation淡入淡出延迟

我想做一个非常简单的alphaanimation,但我找不到一个有效的方法。

这个想法是在视图上执行这个animation:

我试图用AnimationSet来实现:

AnimationSet animationSet = new AnimationSet(true); Animation animation1 = new AnimationUtils.loadAnimation(this, android.R.anim.fade_in); animation1.setDuration(1000); Animation animation2 = new AnimationUtils.loadAnimation(this, android.R.anim.fade_out); animation2.setDuration(1000); animation2.setStartOffset(5000); Animation animation3 = new AlphaAnimation(0.0f, 0.0f); animation3.setDuration(4000) animation3.setStartOffset(6000); animationSet.add(animation1); animationSet.add(animation2); animationSet.add(animation3); 

等等..

但它接触到第三个animation搞乱所有的alphaanimation,我认为这会导致Androidpipe理这种types的animation的方式内​​部不一致。

任何想法?

谢谢。

    好的记住这两点来解决这个问题




    这里是代码:

      animation1 = new AlphaAnimation(0.0f, 1.0f); animation1.setDuration(1000); animation1.setStartOffset(5000); animation2 = new AlphaAnimation(1.0f, 0.0f); animation2.setDuration(1000); animation2.setStartOffset(5000); textView.startAnimation(animation1); 

    但是为了永久循环,我将使用AnimationListener因为repeatCount是buggy:

      animation1 = new AlphaAnimation(0.0f, 1.0f); animation1.setDuration(1000); animation1.setStartOffset(5000); //animation1 AnimationListener animation1.setAnimationListener(new AnimationListener(){ @Override public void onAnimationEnd(Animation arg0) { // start animation2 when animation1 ends (continue) textView.startAnimation(animation2); } @Override public void onAnimationRepeat(Animation arg0) { // TODO Auto-generated method stub } @Override public void onAnimationStart(Animation arg0) { // TODO Auto-generated method stub } }); animation2 = new AlphaAnimation(1.0f, 0.0f); animation2.setDuration(1000); animation2.setStartOffset(5000); //animation2 AnimationListener animation2.setAnimationListener(new AnimationListener(){ @Override public void onAnimationEnd(Animation arg0) { // start animation1 when animation2 ends (repeat) textView.startAnimation(animation1); } @Override public void onAnimationRepeat(Animation arg0) { // TODO Auto-generated method stub } @Override public void onAnimationStart(Animation arg0) { // TODO Auto-generated method stub } }); textView.startAnimation(animation1); 

    有一个更简单的解决scheme。

    让我们假设你的视图处于状态GONE。 为了使其可见性更具活力:

     yourView.setVisibility(View.VISIBLE); yourView.animate().alpha(1).setDuration(300); 

    通过相同的方式,您可以添加animation侦听器。

    这也适用于缩放和翻译animation。

    以上就是android开发分享Android的阿尔法animation淡入淡出延迟相关内容,想了解更多android开发(异常处理)及android游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/addevelopment/512352.html

      (0)
      上一篇 2020年11月27日
      下一篇 2020年11月27日

      精彩推荐