Android runs on a wide range of gadgets which have totally different display screen sizes
and pixel densities. The system performs fundamental scaling and resizing to adapt
your person interface to totally different screens, however there’s extra work you need to do
to make sure your UI gracefully adapts for every kind of display screen.
This web page gives an summary of those subjects and the options accessible on
Android to assist your app adapt accordingly.
For extra particular directions about learn how to construct your app for these display screen
variations, see the next pages:
- Help Totally different Display Sizes
- Help Totally different Pixel Densities
The display screen dimension is the seen house offered to your app UI.
The display screen dimension because it’s identified to your app isn’t the precise dimension of the system
display screen—it takes into consideration the display screen orientation, system decorations (such
because the navigation bar), and window configuration modifications (akin to when the person
allows multi-window mode).
By default, Android resizes your app structure to suit the present display screen.
To make sure your structure resizes properly for even small variations in display screen dimension, you
must implement your structure with flexibility in thoughts. The core precept you
should observe is to keep away from hard-coding the place and dimension of your UI parts.
As an alternative, enable view sizes to stretch and specify view positions relative to the
dad or mum view or different sibling views so your meant order and relative sizes
stay the identical because the structure grows.
Be taught extra about versatile layouts.
A versatile structure is essential, however you must also design totally different
layouts that optimize the person expertise for the accessible house on totally different
gadgets akin to telephones and tablets. So Android means that you can present different
structure recordsdata that the system applies at runtime based mostly on the present system’s
display screen dimension.
Discover ways to create different layouts.
As a result of your structure ought to stretch to suit the present display screen, so too ought to the
bitmaps that you just connect to any of the structure views.
Nonetheless, stretching an abnormal bitmap in arbitrary instructions may end up in
unusual scaling artifacts and skewed photographs.
To resolve this, Android helps nine-patch bitmaps wherein you specify small
pixel areas which might be stretchable—the remainder of the picture stay unscaled.
Be taught extra about nine-patch bitmaps.
The pixel density is the variety of pixels inside a bodily space of the
display screen and is known as dpi (dots per inch). That is totally different
from the decision, which is the entire variety of pixels on a display screen.
Your app achieves “density independence” when it preserves the bodily dimension
(from the person’s viewpoint) of your UI design when displayed on screens with
totally different pixel densities (as proven in determine 2). Sustaining density
independence is essential as a result of, with out it, a UI aspect (akin to a button)
may seem bigger on a low-density display screen and smaller on a high-density display screen
(as a result of when the pixels are bigger—as proven in determine 2—a number of pixels can go a
The Android system helps you obtain density independence by offering
density-independent pixels (dp or dip) as a unit of measurement that
you need to use as an alternative of pixels (px).
Be taught extra about density unbiased pixels.
To make sure your photographs seem at their finest on all screens, you need to present
different bitmaps to match every display screen density. For instance, in case your app
gives bitmaps just for medium density (mdpi) screens, Android
scales them up when on a high-density display screen in order that the picture occupies the identical
bodily house on the display screen. This may trigger seen scaling artifacts in
bitmaps. So your app ought to embody different bitmaps at the next decision.
Discover ways to present different bitmaps.
For easy varieties of photographs (often icons), you may keep away from creating separate
photographs for every density by utilizing vector graphics. As a result of vector graphics outline
the illustration with geometric line paths as an alternative of pixels, they are often drawn
at any dimension with out scaling artifacts.
Be taught extra about utilizing vector graphics.
Put on OS, TV, Auto, and Chrome OS
The suggestions above apply to all Android type elements, however if you need
to construct an app for Put on OS, Android TV, Android Auto, or Chrome OS
gadgets, you could do a bit extra work.
Every of those gadgets have their very own person interplay mannequin that your app ought to
accommodate. In some instances, akin to for Put on OS, you need to re-think
your app’s person expertise and construct an app that is specialised for that system.
And to help Chrome OS gadgets (such because the Google Pixelbook), you may want
solely slight modifications to your current app to help keyboard/mouse
interplay and a a lot bigger display screen.
To help these gadgets, consult with the next developer guides:
- Constructing Apps for Put on OS
- Constructing Apps for Android TV
- Constructing Apps for Android Auto
- Constructing Apps for Chrome OS
Foldable gadgets usually have a number of shows with totally different shows (or
even mixtures of shows) turning into lively for various states of the
system folding. Following the rules on this doc will assist your app to
adapt to these altering configurations. Nonetheless, some configurations could have
uncommon side ratios, so it’s price testing how your app behaves on a spread
Normally, an app that works properly in multi-window
mode for numerous window sizes will
additionally behave properly on foldable gadgets.
Be taught extra about constructing apps for foldables
Though the Android framework and instruments present the whole lot you could make
an app accessible to all display screen configurations, you continue to may determine you
don’t need your app accessible on some display screen configurations as a consequence of some type
of incompatibility. In that case, you may
declare your app helps solely particular screens.