Use a layout folder for more than one size

Asked

Viewed 320 times

2

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

My layout folders are:

layout > Has almost all layouts

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

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

Until then the result is as follows:

Screen A:

  • tablet, appears the modification
  • smatphone does not present the modification

Screen B:

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

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

I don’t want to do numerous layouts!

  • What is the minSdkVersion of its application?

  • Is the 17 ( android 4 )

1 answer

1


The reason is simple, see what it says to 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 don’t 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 no Resources that Better match (for example, a large-size screen will use normal-size screen Resources if necessary).

The paragraph in Bold explains why the tablet(large-size) is using the resources defined for normal-size:

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

You set resources for layout-normal-land but not to layout-large-land.
The tablet, when in position Landscape, as it does not find resources defined for this situation(layout-large-land), will use the features defined for a smaller screen(layout-normal-land).


Android version 3.2 was introduced new size qualifiers that offer more control in defining the features to use for each screen size.

Now, the sizes you specify using these qualifiers, are not the actual screen sizes. Instead, sizes are for width or height in units dp which must 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, <N> dps width available for your interface.
    Examples of use: sw600dp, sw720dp

  • Screen width available: w<N>dp
    Specifies the minimum width <N> needed in dps so that resources can be used. The corresponding system value for the width changes when the screen orientation switches between portrait and landscape to reflect the actual current 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 orientation qualifiers together.
    Examples of use: w600dp, w720dp

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

  • Right, I created a layout-large-land folder and put the layout copy that I didn’t want to be affected.

  • 1

    Consider using the new qualifiers, they usually allow you to decrease the number of layouts to be defined.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.