Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make a view to appear gradually, not suddenly

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.

like image 993
Gabrielle Avatar asked Dec 15 '11 07:12

Gabrielle


1 Answers

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.

like image 103
mmeyer Avatar answered Oct 31 '22 04:10

mmeyer