简体   繁体   中英

Android layouts - one layout for all screen sizes?

We have a confusion about the best practices of Android layout design. Up to now we designed layouts either for each screen sizes (hdpi, XHDPI, xxhdpi.... ) or for width/height concept (sw, sh etc folder structure). Any away we had multiple layout to support multiple screen sizes. Sometimes most of they are just a copy of hdpi as Android managed to scale things properly.

Now we hired a senior Android developer with 5. 5 Years of experience and he prefers to write only one layout to all screen sizes. He argues that this is the latest way. He only write one layout and when it comes to images he add them to different drawable folders (hdpi drawable folder etc) with different sizes to match across all screens

At the moment I am also confused thinking whether I really missed an industry standard, because this new guy's past UIs also seems pretty good.

Any advice on this please?

Up to now we designed layouts either for each screen sizes (hdpi, XHDPI, xxhdpi.... )

Those are not sizes. Those are densities.

or for width/height concept (sw, sh etc folder structure)

Those are sizes.

He only write one layout and when it comes to images he add them to drawable folders (hdpi drawable folder etc) with different sizes to match across all screens... whether I really missed an industry standard

Having layouts based upon densities has been a code smell since late 2009, when the concept of screen densities was introduced. Having drawables based upon densities has been a best practice over the same timeframe.

In terms of the "one layout" portion, that may not be practical in all cases:

  • Different orientations (portrait vs. landscape) may require different layouts (eg, to get forms to fit without scrolling)

  • Substantially different screen sizes (eg, phones versus tablets) may require different layouts

  • Substantially different UI approaches (eg, watches vs. handheld mobile devices vs. TVs) usually require different layouts

you should fix your height and width of the view in dimension file for various resolution example:

values folder:

90dp 75dp

values-hdpi folder:

    <dimen name="width">100dp</dimen>
    <dimen name="height">85dp</dimen>

like this do for mdpi,,xhdpi,xxhdpi and put this in your view.

android:layout_width="@dimen/width" android:layout_height="@dimen/height"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM