Android - Fadeout animation for splash screen

一笑奈何 提交于 2019-12-02 23:51:46

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

@android:style/Theme.Translucent

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!

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!