Consider a machine with the following resolution:
x 480
1024x768 x 600
1024x768 x 768
800 x
1920x1080 x 1200
2048 x 1536
A total of six kinds of resolution machines, if according to DP units to subdivide can be divided into several?
First through the context. getresources (). Getdisplaymetrics (). Density Gets the screen density to the current machine, and then through DP = px/density the conversion can be made to the size of the machine corresponding to the DP unit. For example, I separate the device corresponding to the dpin my hand, the value is as follows:
Device px size |
Device screen density dpi |
Device DP size |
The corresponding minimum width |
x 480 |
1 |
x 480 |
Sw480dp |
1024x768 x 600 |
1 |
1024x768 x 600 |
Sw600dp |
1024x768 x 768 |
1 |
1024x768 x 768 |
Sw720dp |
800 x |
1, another machine is 1.5 |
the other is 853 x 533 |
SW720DP Another one is sw480dp . |
1920x1080 x 1200 |
1.5 |
800 x |
Sw720dp |
2048 x 1536 |
2 |
1024x768 x 768 |
Sw720dp |
table one device dp minimum width description table
The concept of the minimum width can be seen in the following description:
The basic size of the screen refers to the shortest available screen area. In particular, the minimum width of the device is the shortest possible width and height of the screen (it can also be seen as the minimum width of the screen). This allows you to use this qualifier to ensure that the application has at least <n>dp width available for the UI interface, regardless of the current orientation of the screen.
For example, if the layout requires at least 600dp minimum screen size at any time, you can use this qualifier to create a layout resource in the res/layout-sw600dp/ directory. These resources are only used when the size of the available screen is at least 600DP , regardless of whether the 600DP is a user-perceived height or width. The minimum width is the fixed screen size feature of the device, and the minimum width of the device does not change when the orientation of the screen changes.
The minimum width of the device requires consideration of screen decorations and system UI occupancy. For example, if a device has some fixed UI elements that take up a certain amount of screen space along the minimum width of the axis, the minimum width of the system declaration is smaller than the actual screen size, because the portion of the pixel that is occupied by the system on the user application UI invalid. Therefore, this value should be the minimum actual size required for the application layout (typically, this value is the minimum width supported by the layout, regardless of the current orientation of the screen).
Here are some values for the common screen size that you can use:1.320, devices configured for the following screens:
240x320ldpi(QVGA handheld device)
320X480MDPI(handheld device)
480X800HDPI(High resolution handheld device)
2.480, for 480x800mdpi screens (flatbed or handheld devices)
3.600, screen for 600x1024mdip (7 -inch tablet)
4.720, for the 720x1280mdip screen ( inch tablet)
When an application provides multiple minimum width qualifier resource catalogs with different values, the system uses the resource that is closest (not exceeding) the minimum width of the device.
This qualifier is added to the API level .
Also see the ANDROID:REQUIRESSMALLESTWIDTHDP property, which declares the smallest minimum width compatible with your application, and SMALLESTSCREENWIDTHDP The configuration field holds the value of the device's minimum width.
As can be seen from table one, seven devices, six resolutions correspond to the minimum width of the three, so we can adapt to the different minimum width of the case to complete the above all models of the adaptation. How to fit different models according to the minimum width? In fact, it is very simple, just need to customize the files within the following folders can be.
Res/layout-sw320dp
Res/layout-sw480dp
Res/layout-sw600dp
Res/layout-sw720dp
Res/values-sw320dp
Res/values-sw480dp
Res/values-sw600dp
Res/lvalues-sw720dp
For example, if I am doing the first machine, all the UI dimensions are configured in 720DP machines, then the minimum width is 600dp . The machine should be all size divided by 1.2, corresponding to a minimum width of 480dp machine should be all size size divided by 1.5, In turn.
Of course, the premise is that you are in the layout of the dimensions are in DP units, the font with sp or dp units.