美文网首页
Android View显示隐藏渐变动画

Android View显示隐藏渐变动画

作者: 古早味蛋糕 | 来源:发表于2022-11-19 20:03 被阅读0次
    public static void fadeIn(final View view) {
        if (view.getVisibility() == View.VISIBLE) {
            return;
        }
        Animation animation = new AlphaAnimation(0F, 1F);
        animation.setDuration(500);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
    
            }
    
            @Override
            public void onAnimationEnd(Animation animation) {
                view.setEnabled(true);
            }
    
            @Override
            public void onAnimationRepeat(Animation animation) {
    
            }
        });
        view.startAnimation(animation);
        view.setVisibility(View.VISIBLE);
    }
    
    public static void fadeOut(final View view) {
        if (view.getVisibility() != View.VISIBLE) {
            return;
        }
    
        // Since the button is still clickable before fade-out animation
        // ends, we disable the button first to block click.
        view.setEnabled(false);
        Animation animation = new AlphaAnimation(1F, 0F);
        animation.setDuration(500);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
    
            }
    
            @Override
            public void onAnimationEnd(Animation animation) {
                view.setVisibility(View.GONE);
            }
    
            @Override
            public void onAnimationRepeat(Animation animation) {
    
            }
        });
        view.startAnimation(animation);
    }
    

    使用:

                //llcPeakValley.setVisibility(View.GONE);
                AnimationUtil.fadeOut(llcPeakValley);
    
                //llcPeakValley.setVisibility(View.VISIBLE);
                AnimationUtil.fadeIn(llcPeakValley);
    

    转载:Android View显示隐藏渐变动画 - 简书 (jianshu.com)

    相关文章

      网友评论

          本文标题:Android View显示隐藏渐变动画

          本文链接:https://www.haomeiwen.com/subject/izoztdtx.html