Use a layout folder for more than one size

2

I have a Tablet (7 ") and a smatphone (5").

My layout folders are:

layout > It has almost all layouts

layout-large > One of the screens (Screen A) will behave differently for wide

layout-normal-land > One of the screens (Screen B) will behave differently to normal

So far the result is as follows:

Screen A:

  • tablet , you'll see the modification
  • smatphone does not display the modification

Screen B:

  • tablet (land), aparesenta modification
  • smatphone (land) introduces the modification

If the tablet is considered large because it is affected by normal ?
How do I get around this?

I do not want to do lots of layouts!

    
asked by anonymous 30.03.2016 / 21:54

1 answer

1

The reason is simple, check out documentation :

  

Be aware that, when the Android system picks which resources to use at runtime, it uses certain logic to determine the "best matching" resources. That is, the qualifiers you use do not have to exactly match the current screen configuration in all cases in order for the system to use them. Specifically, when selecting resources based on the size qualifiers, the system will use resources designed for a screen smaller than the current screen if there are in resources that better match (for example, the large-size screen will use normal-size screen resources if necessary).

The bold paragraph explains why the tablet is using features defined for normal-size : p>
  

(...) Specifically, when selecting features based on size qualifiers, the system will use the features defined for a screen smaller than the current screen, if there are no features that are best suited (for example, large-size screen will use the resources defined for normal-size screen if necessary).

You have defined features for layout-normal-land but not for layout-large-land . The tablet, when in the landscape position, because it does not find features defined for this situation, will use the features defined for a smaller screen ( layout-normal-land ).

In the Android 3.2 version new size qualifiers that provide more control over the definition of features to use for each screen size.

Now the sizes you specify using these qualifiers are not the actual screen sizes. Instead, the sizes are for the width or height in dp units that will need to be available for the layout .

There are 3 qualifiers:

  • Shorter width: sw<N>dp
    Use this qualifier to ensure that regardless of the current orientation of the screen, your application has at least% w / dps wide available for your interface. Examples of usage: <N> , sw600dp

  • Screen width available: sw720dp
    Specifies the minimum width w<N>dp needed in dps for resources to be used. The system's corresponding value for width changes when the screen orientation toggles between portrait and landscape to reflect the current actual width that is available. Thus, this option can be used to specify the minimum width required for the layout, both in portrait and landscape, avoiding having to use size qualifiers and guidance qualifiers together. Examples of usage: <N> , w600dp

  • Screen height available: w720dp
    The same as the previous only regarding height.
    Most applications will not need this qualifier, considering that it is usually possible to use vertical scroll therefore there is more height available, while the width is more rigid. Examples of usage: h<N>dp , h600dp

31.03.2016 / 11:58