MyTetra Share
Делитесь знаниями!
Пример приложения со сплеш-скрином под Андроид
Автор: Espen Riskedal
Текстовые метки: android, андроид, спелеш-скрин, splash screen, пример, код , sample
Раздел: Компьютер - Android - Программирование под Андроид

Здесь рассказывается о демонстрационном приложении, в котором отображается стартовый экран (сплеш-скрин). Даны ссылки на исходный код.

Сплеш-скрин представляет собой отдельный слой, на котором находятся три картинки: картинка заднего фона, которая выводится с повторением (замощением площади), картика приложения (в центре экрана) и картинка с логотипом производителя (внизу экрана).

Сплеш-скрин выглядит так:

Splash screen that loads instantaneous

In order to make an app feel fast, it's important that the user sees something immediately when the app launches. I still see many apps that take several seconds to show anything, and it makes me wonder if the developer simply don't know how to achieve this instant gratification. Therefore I've decided to write a small post explaining how to get this done. If your app needs a lighting fast splash screen then this is for you.

Executive summary

Launch an empty activity, with a custom theme where windowBackground is set. The activity launches the main activity after a short delay and then finishes.

The git repo is available here.

You can install the example here.

Do we need a splash screen?

Some of you might be thinking: If you're so slow that you need a splash screen you're doing it wrong! I would normally agree, but there are two reasons why I think it's better to have a splash screen nonetheless. Firstly, inflating a layout on Android is slow, so no matter what you do there will be a delay before the user sees it. Secondly, the main activity often does a lot of stuff, so it is hard to keep it lean.

It's all in the theme

The splash activity is the first activity to be launched. It shows the splash screen and then, after a short delay, it starts the main activity and finishes. The splash activity has no actual content view, and the reason for this is that it takes too long to inflate even the simplest layout. Instead the splash activity uses a custom theme which defines a default windows background  drawable. We set the custom theme in the manifest.

A responsive splash Drawable

A splash screen typically consists of a background and some logos. To make a single drawable that works well across different resolutions and PPIs you need to use the LayerDrawable. The LayerDrawable is a stack of several drawables on top of each other. The stacked drawables can be of different types and can be positioned individually, and you can choose if they are scaled or not.

In my example drawable I use three bitmaps. The first one is a tiled background, the second is the product logo which is positioned a little bit above the middle, and the third one is the company logo positioned in the bottom.

Transitions and progress bar

To make the transition from the splash activity to the main activity smooth I suggest that you override the animation between them. I also suggest that you re-use elements in the splash drawable in the main activity. For example, you can re-use a header or footer. This ties the two activities more together.

If you want to display a progressbar inside the splash activity, then you can add it to the (currently) empty splash layout. It won't inflate and be shown immediately like the background, but it will still be fairly snappy.

MyTetra Share v.0.52
Яндекс индекс цитирования