5

I need to make a certain view to appear/ disappear gradually, step by step and not suddenly. If I use MyView.setvisibility(View.GONE) or MyView.setvisibility(View.VISIBLE) everything happens suddenly. 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 a ViewFlipper. When ViewFlipper contains the rr RelativeLayout I add video to it. I am tring to make video visible when is making the transition for rr but it not worked.

Gabrielle
  • 4,933
  • 13
  • 62
  • 122

1 Answers1

7

View Animations are the simplest way to achieve this IMHO.

place 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 Activity code in probably onResume do smth like:

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

This will give you a fade in over 2.2 secs. Added an interpolater to the xml like the AccelerateDecelerateInterpolator for more natural feeling fades if you like.

mmeyer
  • 3,598
  • 1
  • 19
  • 22
  • 1
    I believe that this is working for images. I tried it for a videoview but it doesn't help me. Thanks a lot anyway. – Gabrielle Dec 15 '11 at 08:12
  • It should work for anything that derives from android.view.View, which VideoView does and thus should accept the setAnimation(). What specifically doesnt seem to be working? – mmeyer Dec 15 '11 at 08:16
  • I edited my question with my code and explain what I'm trying to do. – Gabrielle Dec 15 '11 at 08:19
  • 2
    Doesn't work on VideoView... For my part, I just add a View over the VideoView (Empty View with Background color. ) and I add the animation on It – Tobliug Feb 25 '15 at 20:42