Pular para o conteúdo

Mais visitados

Visitados recentemente


Screen Size Compatibility for Chromebooks

The implementation of Android apps on Chrome OS includes basic multi-window support. Instead of automatically drawing over the full screen, Android renders apps on Chrome OS into layouts that are appropriate for the form factor.

Resizing Tasks and Windows

Because the activity's window size can change, activities should read the activities' resolution upon start. Activities should react to resolution changes by calling onConfigurationChanged(..). For example, to avoid losing user's work upon maximization, you can do either of the following:

  • Handle configuration changes dynamically by adding android:configChanges="screenSize|smallestScreenSize|orientation|screenLayout" to the activity's manifest.
  • Restore the previous state by using onSaveInstanceState to make the transition as simple as possible. This is applicable where requesting a restart is the only option.

When looking for the current configuration, always use the configuration from your current activity in getResources().getConfiguration(). Do not use the configuration from your background activity or the one from the system resource. The background activity does not have a size, and the system's configuration may contain multiple windows with conflicting sizes and orientations, so no usable data can be extracted.

Another important consideration is that window content bounds can change. For example, the area within the window that is used by the app can change if the window gets too big to fit the screen. Consider the following guidelines:

  • Apps that utilize Android's layout process should automatically be laid out in the available space.
  • Native apps should read the available area and monitor size changes to avoid having inaccessible UI elements. Call the following methods to determine the initial available size for this surface:
    • NativeActivity.mLastContent[X/Y/Width/Height]()
    • findViewById(android.R.id.content).get[Width/Height]()
    Continuous monitoring can be done via observer:
    • NativeActivity.onContentRectChangedNative()
    • NativeActivity.onGlobalLayout()
    • Add a listener to view.addOnLayoutChangeListener(findViewById(android.R.id.content))
    If the app is pre-scaling its artwork, it should do this every time the resolution changes.

The system supports free resizing; however, not all apps were written with resizing in mind. Here are some potential issues to look for:

  • Handle resizing seamlessly. You can get resized at any point in time because of all kind of reasons. As such it is really important to be able to save and restore your state as well as possible via onSaveInstanceState if a restart becomes necessary. Note that this is also beneficial for Android in general.
  • Also make sure that an activity restart is fast by caching objects you have previously allocated. If you do not use the frameworks layout mechanisms—so your app would for example use OpenGL and scale the content, or some other logic kicks in—you should listen to onConfigurationChanged events to avoid activity restarting. Make sure to specify all change events you can handle dynamically.
  • If you do not want to get resized you should specify this in your manifest file accordingly.
  • It is important to note that the window size is not the screen size and that you probably never need the screen size anyways. To get the window size you should use Activity.getResources().getConfiguration().screenWidth and Activity.getResources().getConfiguration().screenHeight in DP.

To get your current configuration, always use your activity's resource and get the configuration from there, since otherwise you might end up looking at "something," such as the screen properties.

Note that the screen position can change as well. So be sure to always use the system to do window-to-screen space calculations or vice versa.

If you are using Android's view system, your window should get layed out automatically with a size change.

If you do not use the view system and take over the surface, your app must handle size changes on your own.

Native apps should use the mLastContent members—or getting the content view to get the initial size.

Once the app is running it should listen to onContentRectChangedNative or onGlobalLayout events to react to size changes.

Note that with a size change an app should rescale or reload layouts, artwork and update input areas.


To fill the screen with more information, you can specify different layouts, or you could create the layout dynamically for the requested size. Note that dynamic generation is generally not recommended, but might sometimes be a possibility.

Apps that do not use the layout system should avoid restarting for a configuration change as they might be really expensive. These changes can happen because of obvious reasons like window size changes, but also for non obvious ones—like a device mode conversion. Changing from laptop into tablet would for example report a change that the physical keyboard went away. A restart which makes the user wait or even lose work unexpectedly is not a good experience.

Make sure that your code does not try to access UI elements that have gone away due to a dynamic resize operation.

Monitoring View Hierarchy Changes

Adding a window control caption can cause some problems. Consider the following recommendations:

Other Considerations

Here are some other aspects to consider:

Note: We recommend that you test your app to ensure that it handles changes in window size appropriately.

Este site usa cookies para armazenar suas preferências quanto às opções de idioma e exibição específicas ao site.

Receba as dicas e notícias mais recentes para desenvolvedores Android que ajudarão você a ter sucesso no Google Play.

* Campos obrigatórios


Siga o Google Developers no WeChat

Navegar neste site em ?

Você solicitou uma página em , mas sua preferência de idioma para este site está definida como .

Quer alterar sua preferência de idioma e navegar neste site em ? Para alterar a preferência de idioma depois, use o menu de idiomas na parte inferior de cada página.

É preciso ter o nível de API ou superior para esta aula

Este documento está oculto porque o nível de API selecionado para a documentação é o . Para alterar o nível, clique no seletor acima da barra de navegação esquerda.

Para mais informações sobre como especificar o nível de API que o seu app precisa, leia o artigo Compatibilidade com diferentes versões de plataforma.

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)