Ereck Taut
Ereck Taut

Reputation: 65

Launch screen(image view) fade out

I have made a launch screen for my app which makes a Imageview visible for 4 seconds after launch. Then it switches the visibility of the Imageview and the web view so that the web view is now visible. How can i make a fadeout effect when the Imageview disappears?

This is the code I use for switching the visibility

new Handler().postDelayed(new Runnable() {
        public void run() {
            findViewById(R.id.imageLoading1).setVisibility(View.GONE);
            findViewById(R.id.webMain).setVisibility(View.VISIBLE);
        }
    }, 4000);

Upvotes: 0

Views: 250

Answers (1)

Eoin
Eoin

Reputation: 833

The reason your code doesn't work is that Handler().postdelayed(Runnable, int) waits for the specified time and then executes the Runnable. What you need to do is to change the transparency of the views.

To fade one view in while fading another out, try this:

First set the WebView to fade in over 4 seconds:

View web = findViewById(R.id.webMain);

web.setAlpha(0f);
web.setVisibility(View.VISIBLE);

web.animate()
        .alpha(1f)
        .setDuration(4000)
        .setListener(null);

Next set the ImageView to fade out:

View image = findViewById(R.id.imageLoading1);
image.animate()
        .alpha(0f)
        .setDuration(4000)
        .setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                // Now that the ImageView is fully transparent, hide it.
                image.setVisibility(View.GONE);
            }
        });

The two views should crossfade evenly. See this tutorial at Android Developers for more info and an animation.

Hope this helps!

Upvotes: 1

Related Questions