How to make a look appear gradually, not suddenly

I need to make a certain idea in order to appear / disappear gradually, step by step, and not suddenly. If I use MyView.setvisibility(View.GONE) or MyView.setvisibility(View.VISIBLE) , everything happens all of a sudden. Any idea how to do this?

Thanks in advance.

Here is my code:

  animFlipInNext = AnimationUtils.loadAnimation(this, R.anim.push_left_in); animFlipInNext.setDuration(2000); animFlipInNext .setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { System.out.println("AnimStart- LeftIn" + " Will be displayed " + vf.getDisplayedChild()); if (vf.getCurrentView().equals(rr)) { System.out.println("begin layout for video"); rr.addView(myVideoView); myVideoView.setAnimation(AnimationUtils.loadAnimation(context, R.anim.fade_in)); /* myVideoView.startAnimation(new MyScaler(1.0f, 1.0f, 0.0f, 1.0f, 2500, myVideoView, true));*/ } } @Override public void onAnimationRepeat(Animation animation) { System.out.println("AnimRepeat-LeftIn"); } @Override public void onAnimationEnd(Animation animation) { System.out.println("Anim end " + vf.getDisplayedChild()); if (vf.getCurrentView().equals(rr)) { System.out.println("layout for videoView"); rr.removeAllViews(); vf.stopFlipping(); myVideoView.start(); } } }); 

I have an animation for ViewFlipper. When the ViewFlipper contains rr RelativeLayout , I add a video to it. I try to make the video visible when it makes the switch to rr , but it did not work.

+4
source share
1 answer

Watching animations is the easiest way to achieve this IMHO.

put this in / res / anim / fade _in.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:duration="2200"></alpha> </set> 

Then in your action, the code will probably look like this:

 someView.setAnimation(AnimationUtils.loadAnimation(context, R.anim.fade_in)); 

This will give you attenuation in more than 2.2 seconds. Added interpolator for xml, such as AccelerateDecelerateInterpolator, for a more natural feel it disappears if you like.

+6
source

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


All Articles