Animate visibility of a view from gone to visible with animation

前端 未结 5 734
傲寒
傲寒 2021-02-01 17:53

I have a view that is invisible by default(Just for the first time).

Now I need to switch the visibility to VISIBLE with this animation

5条回答
  •  孤城傲影
    2021-02-01 18:25

    This is the best way to animate views visibility :

    private void viewGoneAnimator(final View view) {
    
        view.animate()
                .alpha(0f)
                .setDuration(500)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        view.setVisibility(View.GONE);
                    }
                });
    
    }
    
    private void viewVisibleAnimator(final View view) {
    
        view.animate()
                .alpha(1f)
                .setDuration(500)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        view.setVisibility(VISIBLE);
                    }
                });
    
    }
    

    And then call this method wherever you wanted to make a view visible or gone and give the intended view to methods as the parameter.

提交回复
热议问题