Resource 包匹配顺序

Configuration Qualifier Values Description
MCC and MNC Examples:
mcc310
mcc310-mnc004
mcc208-mnc00
etc.

The mobile country code (MCC), optionally followed by mobile network code (MNC) from the SIM card in the device. For example,mcc310 is U.S. on any carrier, mcc310-mnc004 is U.S. on Verizon, andmcc208-mnc00 is France on Orange.

If the device uses a radio connection (GSM phone), the MCC and MNC values come from the SIM card.

You can also use the MCC alone (for example, to include country-specific legalresources in your application). If you need to specify based on the language only, then use thelanguage and region qualifier instead (discussed next). If you decide to use the MCC andMNC qualifier, you should do so with care and test that it works as expected.

Also see the configuration fields mcc, andmnc, which indicate the current mobile country codeand mobile network code, respectively.

Language and region Examples:
en
fr
en-rUS
fr-rFR
fr-rCA
etc.

The language is defined by a two-letter ISO 639-1 language code, optionally followed by a two letter ISO 3166-1-alpha-2 region code (preceded by lowercase "r").

The codes are not case-sensitive; the r prefix is used to distinguish the region portion. You cannot specify a region alone.

This can change during the lifeof your application if the user changes his or her language in the system settings. SeeHandling Runtime Changes for information abouthow this can affect your application during runtime.

See Localization for a complete guide to localizingyour application for other languages.

Also see the locale configuration field, whichindicates the current locale.

smallestWidth sw<N>dp

Examples:
sw320dp
sw600dp
sw720dp
etc.

The fundamental size of a screen, as indicated by the shortest dimension of the availablescreen area. Specifically, the device's smallestWidth is the shortest of the screen's availableheight and width (you may also think of it as the "smallest possible width" for the screen). You canuse this qualifier to ensure that, regardless of the screen's current orientation, yourapplication's has at least<N> dps of width available for it UI.

For example, if your layout requires that its smallest dimension of screen area be atleast 600 dp at all times, then you can use this qualifer to create the layout resources,res/layout-sw600dp/. The system will use these resources only when the smallest dimension ofavailable screen is at least 600dp, regardless of whether the 600dp side is the user-perceivedheight or width. The smallestWidth is a fixed screen size characteristic of the device; thedevice's smallestWidth does not change when the screen's orientation changes.

The smallestWidth of a device takes into account screen decorations and system UI. Forexample, if the device has some persistent UI elements on the screen that account for space alongthe axis of the smallestWidth, the system declares the smallestWidth to be smaller than the actualscreen size, because those are screen pixels not available for your UI. Thus, the value you useshould be the actual smallest dimensionrequired by your layout (usually, this value is the"smallest width" that your layout supports, regardless of the screen's current orientation).

Some values you might use here for common screen sizes:

  • 320, for devices with screen configurations such as:
    • 240x320 ldpi (QVGA handset)
    • 320x480 mdpi (handset)
    • 480x800 hdpi (high density handset)
  • 480, for screens such as 480x800 mdpi (tablet/handset).
  • 600, for screens such as 600x1024 mdpi (7" tablet).
  • 720, for screens such as 720x1280 mdpi (10" tablet).

When your application provides multiple resource directories with different values for the smallestWidth qualifier, the system uses the one closest to (without exceeding) thedevice's smallestWidth.

Added in API level 13.

Also see the android:requiresSmallestWidthDp attribute, which declares the minimum smallestWidth with whichyour application is compatible, and thesmallestScreenWidthDp configuration field, which holds thedevice's smallestWidth value.

For more information about designing for different screens and using thisqualifier, see theSupportingMultiple Screens developer guide.

Available width w<N>dp

Examples:
w720dp
w1024dp
etc.

Specifies a minimum available screen width, in dp units at which the resource should be used—defined by the<N> value. This configuration value will change when the orientation changes between landscape and portrait to match the current actual width.

When your application provides multiple resource directories with different values for this configuration, the system uses the one closest to (without exceeding) the device's current screen width. The value here takes into account screen decorations, so if the device has some persistent UI elements on the left or right edge of the display, it uses a value for the width that is smaller than the real screen size, accounting for these UI elements and reducing the application's available space.

Added in API level 13.

Also see the screenWidthDp configuration field, which holds the current screen width.

For more information about designing for different screens and using thisqualifier, see theSupportingMultiple Screens developer guide.

Available height h<N>dp

Examples:
h720dp
h1024dp
etc.

Specifies a minimum available screen height, in "dp" units at which the resource should be used—defined by the<N> value. This configuration value will change when the orientation changes between landscape and portrait to match the current actual height.

When your application provides multiple resource directories with different values for this configuration, the system uses the one closest to (without exceeding) the device's current screen height. The value here takes into account screen decorations, so if the device has some persistent UI elements on the top or bottom edge of the display, it uses a value for the height that is smaller than the real screen size, accounting for these UI elements and reducing the application's available space. Screen decorations that are not fixed (such as a phone status bar that can be hidden when full screen) arenot accounted for here, nor are window decorations like the title bar or action bar, so applications must be prepared to deal with a somewhat smaller space than they specify.

Added in API level 13.

Also see the screenHeightDp configuration field, which holds the current screen width.

For more information about designing for different screens and using thisqualifier, see theSupportingMultiple Screens developer guide.

Screen size small
normal
large
xlarge
  • small: Screens that are of similar size to a low-density QVGA screen. The minimum layout size for a small screen is approximately 320x426 dp units. Examples are QVGA low density and VGA high density.
  • normal: Screens that are of similar size to a medium-density HVGA screen. The minimum layout size for a normal screen is approximately 320x470 dp units. Examples of such screens a WQVGA low density, HVGA medium density, WVGA high density.
  • large: Screens that are of similar size to a medium-density VGA screen. The minimum layout size for a large screen is approximately 480x640 dp units. Examples are VGA and WVGA medium density screens.
  • xlarge: Screens that are considerably larger than the traditional medium-density HVGA screen. The minimum layout size for an xlarge screen is approximately 720x960 dp units. In most cases, devices with extra large screens would be too large to carry in a pocket and would most likely be tablet-style devices. Added in API level 9.

Note: Using a size qualifier does not imply that theresources areonly for screens of that size. If you do not provide alternativeresources with qualifiers that better match the current device configuration, the system may usewhichever resources are thebest match.

Caution: If all your resources use a size qualifier thatislarger than the current screen, the system will not use them and yourapplication will crash at runtime (for example, if all layout resources are tagged with thexlarge qualifier, but the device is a normal-size screen).

Added in API level 4.

See Supporting MultipleScreens for more information.

Also see the screenLayout configuration field,which indicates whether the screen is small, normal,or large.

Screen aspect long
notlong
  • long: Long screens, such as WQVGA, WVGA, FWVGA
  • notlong: Not long screens, such as QVGA, HVGA, and VGA

Added in API level 4.

This is based purely on the aspect ratio of the screen (a "long" screen is wider). Thisis not related to the screen orientation.

Also see the screenLayout configuration field,which indicates whether the screen is long.

Screen orientation port
land
  • port: Device is in portrait orientation (vertical)
  • land: Device is in landscape orientation (horizontal)

This can change during the life of your application if the user rotates thescreen. SeeHandling Runtime Changes for information abouthow this affects your application during runtime.

Also see the orientation configuration field,which indicates the current device orientation.

UI mode car
desk
television
appliance
  • car: Device is displaying in a car dock
  • desk: Device is displaying in a desk dock
  • television: Device is displaying on a television, providing a "ten foot" experience where its UI is on a large screen that the user is far away from, primarily oriented around DPAD or other non-pointer interaction
  • appliance: Device is serving as an appliance, with no display

Added in API level 8, television added in API 13.

This can change during the life of your application if the user places the device in adock. You can enable or disable some of these modes usingUiModeManager. SeeHandling Runtime Changes forinformation about how this affects your application during runtime.

Night mode night
notnight
  • night: Night time
  • notnight: Day time

Added in API level 8.

This can change during the life of your application if night mode is left inauto mode (default), in which case the mode changes based on the time of day. You can enableor disable this mode usingUiModeManager. SeeHandling Runtime Changes for information about how this affects yourapplication during runtime.

Screen pixel density (dpi) ldpi
mdpi
hdpi
xhdpi
nodpi
tvdpi
  • ldpi: Low-density screens; approximately 120dpi.
  • mdpi: Medium-density (on traditional HVGA) screens; approximately160dpi.
  • hdpi: High-density screens; approximately 240dpi.
  • xhdpi: Extra high-density screens; approximately 320dpi. Added in APILevel 8
  • nodpi: This can be used for bitmap resources that you do not want to be scaledto match the device density.
  • tvdpi: Screens somewhere between mdpi and hdpi; approximately 213dpi. This isnot considered a "primary" density group. It is mostly intended for televisions and mostapps shouldn't need it—providing mdpi and hdpi resources is sufficient for most apps andthe system will scale them as appropriate. This qualifier was introduced with API level 13.

There is a 3:4:6:8 scaling ratio between the four primary densities (ignoring thetvdpi density). So, a 9x9 bitmap in ldpi is 12x12 in mdpi, 18x18 in hdpi and 24x24 in xhdpi.

If you decide that your image resources don't look good enough on a television orother certain devices and want to try tvdpi resources, the scaling factor is 1.33*mdpi. Forexample, a 100px x 100px image for mdpi screens should be 133px x 133px for tvdpi.

Note: Using a density qualifier does not imply that theresources areonly for screens of that density. If you do not provide alternativeresources with qualifiers that better match the current device configuration, the system may usewhichever resources are thebest match.

See Supporting MultipleScreens for more information about how to handle different screen densities and how Androidmight scale your bitmaps to fit the current density.

Touchscreen type notouch
finger
  • notouch: Device does not have a touchscreen.
  • finger: Device has a touchscreen that is intended to be used through direction interaction of the user's finger.

Also see the touchscreen configuration field,which indicates the type of touchscreen on the device.

Keyboard availability keysexposed
keyshidden
keyssoft
  • keysexposed: Device has a keyboard available. If the device has asoftware keyboard enabled (which is likely), this may be used even when the hardware keyboard isnot exposed to the user, even if the device has no hardware keyboard. If no softwarekeyboard is provided or it's disabled, then this is only used when a hardware keyboard isexposed.
  • keyshidden: Device has a hardware keyboard available but it ishiddenand the device does not have a software keyboard enabled.
  • keyssoft: Device has a software keyboard enabled, whether it'svisible or not.

If you provide keysexposed resources, but not keyssoftresources, the system uses thekeysexposed resources regardless of whether akeyboard is visible, as long as the system has a software keyboard enabled.

This can change during the life of your application if the user opens a hardwarekeyboard. SeeHandling Runtime Changes for information about howthis affects your application during runtime.

Also see the configuration fields hardKeyboardHidden andkeyboardHidden, which indicate the visibility of a hardwarekeyboard and and the visibility of any kind of keyboard (including software), respectively.

Primary text input method nokeys
qwerty
12key
  • nokeys: Device has no hardware keys for text input.
  • qwerty: Device has a hardware qwerty keyboard, whether it's visible to theuseror not.
  • 12key: Device has a hardware 12-key keyboard, whether it's visible to the useror not.

Also see the keyboard configuration field,which indicates the primary text input method available.

Platform Version (API level) Examples:
v3
v4
v7
etc.

The API level supported by the device. For example, v1 for API level1 (devices with Android 1.0 or higher) andv4 for API level 4 (devices with Android1.6 or higher). See the Android API levels document for more informationabout these values.

Caution: Android 1.5 and 1.6 only match resourceswith this qualifier when it exactly matches the platform version. See the section below aboutKnown Issues for more information.

Note: Some configuration qualifiers have been added since Android1.0, so not all versions of Android support all the qualifiers. Using a new qualifier implicitlyadds the platform version qualifier so that older devices are sure to ignore it. For example, usinga w600dp qualifier will automatically include thev13 qualifier, becausethe available-width qualifier was new in API level 13. To avoid any issues, always include a set ofdefault resources (a set of resources withno qualifiers). For more information, see thesection about Providing the Best Device Compatibility withResources.


当有一个包有多个匹配项的时候,数目多的优先匹配。同等数目下,根据该规则匹配

http://developer.android.com/guide/topics/resources/providing-resources.html#table2

http://developer.android.com/guide/topics/resources/providing-resources.html#BestMatch

你可能感兴趣的:(Resource 包匹配顺序)