Animation of visibility of visibility with the gradual disappearance and increase

I have a RelativeLayout whose width and height is greater than the application window, and its visibility is initially set to View.GONE.

I want to show this view when a button is pressed. I would like to fade out and zoom out. Partial smoothing can be easily done using ViewPropertyAnimator. My problem is that I donโ€™t know how to create a view as if it expanded to full size from a smaller size when it disappears.

Is there any built-in animation for this? I did a little work, but did not find anything. Perhaps I am not using the right keywords to search or something like that. Can anybody help?

+5
source share
3 answers
  • Combine ViewPropertyAnimator methods,

so that the animation runs in parallel. AnimationSet is part of the old api, and you should prefer visualizing the animation over it. If you want to use this technique (which is slightly longer for recording and less optmized), you can choose AnimatorSet (Animat- or ...).

Here is a piece of code that solves your problem with animating view properties:

 view.setVisibility(View.VISIBLE); view.setAlpha(0.f); view.setScaleX(0.f); view.setScaleY(0.f); view.animate() .alpha(1.f) .scaleX(1.f).scaleY(1.f) .setDuration(300) .start(); 

A good tutorial on animating view properties here .

+8
source

This can be done using AnimationSet by adding AlphaAnimation and ScaleAnimation.

 AnimationSet animation = new AnimationSet(true); animation.addAnimation(new AlphaAnimation(0.0F, 1.0F)); animation.addAnimation(new ScaleAnimation(0.8f, 1, 0.8f, 1)); // Change args as desired animation.setDuration(300); mView.startAnimation(animation); 
+1
source

You can make sliding left and right view animations respectively.

 TranslateAnimation animate = new TranslateAnimation(0,-view.getWidth(), 0, 0); animate.setDuration(time); view.startAnimation(animate); TranslateAnimation anim = new TranslateAnimation(-400f, 0f,0f,0f); anim.setDuration(time); view.startAnimation(anim ); 
0
source

Source: https://habr.com/ru/post/1202503/


All Articles