Search code examples
androidandroid-layoutscreen-resolutionaspect-ratio

What is the best practice for creating layouts for all screen sizes and all screen densities in Android


Based on what I read (including the official documentation), it is suggested to create separate layouts, separate drawables, separate dimens.xml files to fit all screen sizes and screen densities but from what I see, there are more than 100 different combinations of screen size/screen density of phones and creating unique layouts/drawables for each one of them is next to impossible.

The same result can be achieved by simply adjusting a single layout programmatically, however, no one suggests this approach at all. Why?

Even if I use dp in layouts in sizing the elements, it will still look different on different densities.

Let's say you have layouts for large screen devices with xhdpi density, do you make your app available to only those devices? Seems improbable.

How could someone possibly make an app that would fit all screen sizes/screen density?

There must be an optimal approach in creating layouts for all screen sizes and all screen densities but what? I'm actually REAALLY lost. Can anyone provide a simple project that somehow does this?

Reference: Is there a list of screen resolutions for all Android based phones and tablets?


Solution

  • I have some solutions for you

    1. Use ConstraintLayout (https://developer.android.com/training/constraint-layout/)
    2. Use PercentRelativeLayout (https://developer.android.com/reference/android/support/percent/PercentRelativeLayout)
    3. Sdp converter (https://github.com/intuit/sdp)

    In my case. I use all of them. They can work together as well.