Android - Fadeout animation for splash screen

2019-03-15 17:08发布

I want to add fadeout animation for my splash screen, that is while closing the splash screen I want to bring the fadeout animation effect.

Here are the codes which I have tried.

overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

But the above can be used only from 2.0. Ny app should support from 1.5.

So I have set the following animation for my main activity.

getWindow().setWindowAnimations(android.R.style.Animation_Toast);

OR

getWindow().setWindowAnimations(R.style.Theme_FadeIn);

My Theme.FadeIn contains

<style name="Theme.FadeIn">
<item name="android:windowNoTitle">true</item>
<item name="android:activityOpenEnterAnimation">@anim/fade_in</item>   
</style>

Now I can see the fadein effect, but I can see the blackscreen.

How to get this fadein or fadeout effect without blackscreen.

3条回答
We Are One
2楼-- · 2019-03-15 17:22

You could try to make your activity translucent... take a look at the translucent theme in the sdk

@android:style/Theme.Translucent
查看更多
该账号已被封号
3楼-- · 2019-03-15 17:29

SWDeveloper,

While it has been about a year since I have done any Android development myself, I remember running into this exact problem with my own splash screen.

Unfortunately, for releases before 2.0, I'm fairly certain that the type of transition you want is not possible between activities. That is, in 1.5/1.6, only the built in transition animations can be used between activities.

With that being said, I seem to recall that I used view transition animations within a given activity to produce the kind of effect I was looking for. In otherwords, on my splash screen activity, fading out the initial view to just a blank white view before transitioning to the next activity. The next activity would then start on a blank white view and then fade into the actual view of the activity.

If this seems like a lot of work, you could also alternatively just include your splash screen view in your initial activity and always present it first then fade it out. All within the same activity. Using this method would probably save you time and work, but would lose you some of the modularity that comes with separating out your screens into separate activities.

The animations between views can be achieved (if I remember correctly) via the ViewFlipper widget. The android docs for it can be found here: http://developer.android.com/reference/android/widget/ViewFlipper.html

If I can get a hold of the code base of the app that I wrote, I will try to post up an example later.

Good luck!

查看更多
放荡不羁爱自由
4楼-- · 2019-03-15 17:37

If you're using a separate Activity for your splash screen, you can do the overridePendingTransition call that you've noted is available in Android 2+ only. You can choose to have apps that are built for 2+ do the transition and previous versions simply do the default transition:

try {
    Method method = Activity.class.getMethod("overridePendingTransition", new Class[]{int.class, int.class});
    method.invoke(youractivity, inanimation, outanimation);
} catch (Exception e) {
    // Can't change animation, so do nothing
}

It's better to have your splash screen a part of your main Activity (see this example). When the splash screen is part of your main activity, you can simply assign the animation to the splash screen layout.

查看更多
登录 后发表回答