AndroidManifest. xml & lt; supports-screens & gt; node, androidmanifest

Source: Internet
Author: User

<Supports-screens> node of AndroidManifest. xml, androidmanifest

Reference: http://developer.android.com/guide/topics/manifest/supports-screens-element.html

<Supports-screens> is a subnode of <manifest>. This element is used to specify the screen size supported by the application and enable the screen compatibility mode for larger screens than the screen supported by the application. It is vital to use this element in an application to specify the screen size supported by the application.
If the application adjusts the size attribute to fill the screen, the application must support the given size. Generally, for most applications, the system can do this well, and you do not need to do any extra work to make the application work on a screen larger than a handheld device. However, it is often important to optimize the UI of an application by providing optional layout resources for different screen sizes. For example, if you want to run an Activity layout on a tablet, You need to modify the layout of the Activity.
However, if the size is adjusted to adapt to different screen sizes, but the application cannot work well, you can use the attribute of the <supports-screens> element to control whether the application should be published to a device with a small screen, or use the screen compatibility mode of the system, let the UI zoom in to meet the requirements of large screen. When there is no design for a large screen size and the normal size cannot reach an appropriate result, the screen compatibility mode scales the UI by simulating a normal screen size and a medium density, so that it can fill the entire screen, which will lead to UI blur, so it is better to optimize the large screen.
Note: Android3.2 introduces new attributes: android: requiresSmallestWidthDp, android: compatibleWidthLimitDp, and android: largestWidthLimitDp. If you are developing an Android3.2 or later application, you should use these attributes to declare the screen size supported by the application, rather than based on the general screen size attributes.

Syntax:

<supports-screens android:resizeable=["true"| "false"]    android:smallScreens=["true" | "false"]    android:normalScreens=["true" | "false"]    android:largeScreens=["true" | "false"]    android:xlargeScreens=["true" | "false"]    android:anyDensity=["true" | "false"]    android:requiresSmallestWidthDp="integer"    android:compatibleWidthLimitDp="integer"    android:largestWidthLimitDp="integer"/>

 

Attribute:

Android: resizeable
This attribute is used to indicate whether the application can adjust the size for different screen sizes. The default value is true. If this attribute is set to false, the system runs the application in screen compatibility mode on a large screen.
This attribute has been deprecated. This attribute is introduced to help the application transition from 1.5 to 1.6. When multi-screen support is introduced, it should not be used.

Android: smallScreens
This attribute is used to specify whether the application supports screens with small shapes. A small screen is defined as a screen smaller than a normal (traditional HVGA) screen. External services (such as Google Play) do not provide applications that do not support small screens to small screen devices, because few platforms can ensure that the applications work normally on small screen devices. The default value of this attribute is true.

Android: normalScreens
This attribute is used to indicate whether the application supports normal screen shapes. A typical screen is a HVGA medium-density screen. However, WQVGA low-density and WVGA high-density screens are also considered common screens. The default value of this attribute is true.

Android: largeScreens
This attribute is used to indicate whether the application supports a large screen. A screen of the large type is defined as a screen that is much larger than a screen of a normal handheld device, and in order to make the application work well, be especially careful when using this property, although you can rely on the system to adjust the size to be able to fill the screen.
The default value of this attribute is actually different in some versions, so it is best to explicitly declare this attribute at any time. If it is set to false, the system will enable the screen compatibility mode, so be extra careful.

Android: xlargeScreens
This attribute is used to indicate whether the application supports a large screen. An xlarge screen is defined as a screen larger than a large screen, such as a tablet. In order to make good use of applications, you must be especially careful when using this property, although the UI size of the system can be used to fill the screen.

Android: anyDensity
This attribute specifies whether the application contains resources that can apply to any screen density.
For applications that support Android1.6 (API Level 4) and later, the default value of this attribute is true, and unless absolutely confirmed that this is required for the normal operation of the application, otherwise, it should not be set to false. This attribute must be disabled only when the application directly operates the bitmap.

Android: requiresSmallestWidthDp
Specify the minimum screen width (unit: dp). If the screen width of a device is smaller than the specified value, the application runs in compatible mode.

Android: compatibleWidthLimitDp
When the device screen width (unit: dp) is greater than this value, the system prompts you to switch to compatible mode.

Android: largestWidthLimitDp
When the device screen width (unit: dp) is greater than this value, force this value to switch to compatibility mode.

DisplayMetrics metrics = new DisplayMetrics ();
GetWindowManager (). getDefaultDisplay (). getMetrics (metrics );
Obtains the DisplayMetrics instance, which is used to obtain the pixel density and size of the screen.


How can I obtain the screen size (resolution and density) of an Android phone)

The following code obtains the screen size: In the onCreate method of an Activity, write the following code: DisplayMetrics metric = new DisplayMetrics (); getWindowManager (). getdefadisplay display (). getMetrics (metric); int width = metric. widthPixels; // width (PX) int height = metric. heightPixels; // height (PX) float density = metric. density; // density (0.75/1.0/1.5) int densityDpi = metric. densityDpi; // density DPI (120/160/240) It should be noted that on a low-density cell phone, only the code above cannot obtain the correct size. Therefore, the AndroidManifest. add the supports-screens node to the xml file as follows: <supports-screens android: smallScreens = "true" android: normalScreens = "true" android: largeScreens = "true" android: resizeable = "true" android: anyDensity = "true"/> so that the current Android program supports multiple resolutions, you can get the correct physical size.

How does android get the screen width?

Write the following code in the onCreate method of an Activity:
DisplayMetrics metric = new DisplayMetrics ();
GetWindowManager (). getDefaultDisplay (). getMetrics (metric );
Int width = metric. widthPixels; // screen width (pixels)
Int height = metric. heightPixels; // screen height (pixels)
Float density = metric. density; // screen density (0.75/1.0/1.5)
Int densityDpi = metric. densityDpi; // screen density DPI (120/160/240)
Add the supports-screens node to the AndroidManifest. xml file. The specific content is as follows:
<Supports-screens
Android: smallScreens = "true"
Android: normalScreens = "true"
Android: largeScreens = "true"
Android: resizeable = "true"
Android: anyDensity = "true"/>
In this way, the current Android program supports multiple resolutions, so you can get the correct physical size.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.