Search code examples
androidandroid-layoutandroid-linearlayoutandroid-layout-weight

layout_weight vs multiple sw<dp> screen


I am still confused between the two. Do I have to create multiple layouts for my app like sw600dp and sw720dp if I used a LinearLayout and specified a layout_weight attribute for each view? In the documentation it describes the layout_weight as how much a child will occupy from the screen. So will that be an alternative of creating multiple layouts?


Solution

  • This is more or less an opinion based answer. However, I prefer creating multiple layouts for different sizes.

    xlarge screens are at least 960dp x 720dp

    large screens are at least 640dp x 480dp

    normal screens are at least 470dp x 320dp

    small screens are at least 426dp x 320dp

    So the usage would be creating a new layout file using the screen size parameter. And to finally answer your question: No, it's better to have multiple layouts, but you should always work with a combination of both.

    You sometimes don't want to have the same content on different screen sizes. For example an app cannot upscale from small to a big tablet. On tablets the app should look different and have more content, other locations. You cannot control that in a single file. For simple upscaling you can use a single file and weights. But if you need to make changes to the way the content is displayed, it's better to use different files.

    Source: https://developer.android.com/guide/practices/screens_support.html