Android Common resolutions (MDPI, HDPI, xhdpi, xxhdpi) screen adjustments

Source: Internet
Author: User

After querying to the system service being executed, you can then add the service name to the Dumpsys and view the specified service information.

ADB shell Dumpsys Activity

ADB Shell Dumpsys Cpuinfo

adb shell Dumpsys Battery

adb Shell Dumpsys window (the last part can see the resolution information) =====

-------------------------------------------------

Android developers about DP documentation I've seen n times, the conversion formula for PX and DP I remember very well: px = DP * (dpi/160) , the original DPI here is normalized after the DPI, the possible value is only three (low), (medium), a (high), (Xhigh) Four kinds of, and I understand the actual device is actually real dpi!

-------------------------------------------------------------------------------------------

1 Android phones now common resolution

4:3
VGA 640*480 (Video Graphics Array)
QVGA 320*240 (Quarter VGA)
HVGA 480*320 (half-size VGA)
SVGA 800*600 (Super VGA)
5:3
WVGA 800*480 (Wide VGA)
16:9
FWVGA 854*480 (full Wide VGA)
HD 1920*1080 High Definition
QHD 960*540
720p 1280*720 SD
1080p 1920*1080 HD
1.2 Resolution corresponding DPI
"HVGA mdpi"
"WVGA hdpi"
"FWVGA hdpi"
"QHD hdpi"
"720P xhdpi"
"1080P xxhdpi" ======= "See
2 Considerations for screen adaptation
2.1.1 Androidmanifest.xml Settings
Adding a child element to the Menifest
Android:anydensity= "true" when the application is installed on a different density terminal, the program will load the resources in the xxhdpi, xhdpi, hdpi, MDPI, ldpi directories separately.

Conversely, if set to false, even if you have the same resources under the directory, the application will not voluntarily go to the corresponding directory to find resources:
1) Assuming drawable-hdpi, drawable-mdpi, DRAWABLE-LDPI three directories have a different density representation of the same picture resource, then the system will load the resources in the drawable_mdpi directory,
2) Assume that there are high-density images in the drawable-hpdi, and that there are no corresponding picture resources in the other two directories. Then the system will load the resources in the drawable-hdpi, the other way around.
3) Assume that there is a picture resource in drawable-hdpi,drawable-mdpi, not in drawable-ldpi. The system will load the resources in the drawable-mdpi. Use the closest density level.
2.1.2 Horizontal screen Vertical folder
1) drawable
A) drawable-hdpi the picture applies to horizontal screen and vertical screen;
B) DRAWABLE-LAND-HDPI, when the screen is a horizontal screen. and is high density. A resource loaded into this directory;
C) drawable-port-hdpi when the screen is vertical and high density. Load the resources in this directory. others.
2) Layout
creates Layout-port and Layout-land two folders under the Res folder, with two layout files for vertical and horizontal screens respectively. To adapt to the horizontal screen vertical screen own active switch.
2.2 multi-screen fit 4 Gold principle
1) Use Fill_parent, wrap_content, match when setting control dimensions in the layout file _parent and DP.
in detail. Sets the value of the view's properties Android:layout_width and Android:layout_height. Wrap_content,match_parent or DP is better than PX. The text size should be defined using the SP.
2) do not show detailed pixel values in the program's code. defined in Dimens.xml;
to make the code simple, Android internally uses the PIX to represent the size of the control, but this is based on the current screen. To accommodate multiple screens. Android recommends that developers do not use detailed pixels to represent the size of the control.


3) do not use Absolutelayout (android1.5 is obsolete), can use relativelayout substitution;
4) provide a suitable size picture for different screens.


Different size screen with different size picture, Low:medium:high:extra-high picture size ratio of 3:4:6:8; For example, for medium density (medium) screen your picture pixel size is 48x48. The image size of the low density screen should be 36x36, and the height (high) is 72x72. Extra-high for 96x96.
2.3 Using 9-patch PNG images
When using a picture resource, assume that an extrude occurs due to the reason for the picture processing. Will deform. Causes the interface to shape. The 9-patch PNG image is also a standard PGN image, vacated by a pixel interval around the native PNG image, to identify which parts of the PNG picture can be stretched, which cannot be stretched, the border position on the background, and so on.


"Top, left" defines an extruded area
"Right, bottom" defines the display area, assuming a full-filled background map is used. It is not recommended to set the margin through android:padding, but to define it by 9-patch way.


The Android SDK provides tools to edit 9-patch images, Draw9patch.bat in the Tools folder to instantly see the edited stretch, or edit directly with other image editing tools, but you can't see the effect.


2.4 Different layout
Android phone screen size is different, there are 480x320, 640x360, 800x480 ...
How talent let application oneself adapt to different screen?

actually very easy. Just create a different layout folder under the Res folder, for example: layout-640x360, layout-800x480 ... All layout files are written to R.java after compilation, and the system uses the appropriate layout according to the size of the screen.

Summary: It's best to join Mainifest

<!--for very high resolution, in addition to the corresponding image, you need to add such as the following configuration, to better fit the screen--
<supports-screens
Android:smallscreens= "true"
Android:normalscreens= "true"
Android:largescreens= "true"
Android:anydensity= "true"/>

Inch
Represents inches, which is the physical size of the screen.

Equal to 2.54 centimeters per inch. For example, we often say that the size of the mobile phone screen, 5 (English), 4 (English) inches refers to this unit. These dimensions are the diagonal length of the screen. Suppose the phone's screen is 4 inches, indicating that the screen (viewable area) of the phone is 4 X 2.54 = 10.16 centimeters.
Dpi
DPI is the abbreviation for dots per inch, in dots each, which includes the number of pixels per inch. For example, the 320x480 resolution of the phone, 2 inches wide. 3 inches high, the number of pixels per inch is 320/2=160dpi (landscape) or 480/3=160dpi (portrait), 160 is the dpi of the phone, and the horizontal and vertical values are the same. The reason is that most phone screens use a square pixel point.
Density
Screen density, density and dpi are density = dpi/160
Dp
Also known as dip, device independent pixel, devices independent pixels abbreviation, Android Special Unit, on screen density dpi = 160 screen, 1DP = 1px.
Sp
and DP very similar. Generally used to set the font size. The difference with DP is that it can be scaled according to the user's font size preference.


Android drawable
We should be able to see very many drawable directories after we create a new Android project. correspond to different DPI
drawable-ldpi (dpi=120, density=0.75)
drawable-mdpi (dpi=160, density =1)
drawable-hdpi (dpi=240, density=1.5)
drawable-xhdpi (dpi=320, density=2)
drawable-xxhdpi (dpi=480, density=3)
Some of the Android tutorials on the market are mostly taught to produce a set of image resources for each DPI, which is certainly a solution. But at the same time is also a very stupid method, for art or design to add a lot of work not to say. At the same time it will make your APK package very big. So is there any good way to ensure that the screen is adaptable, but also to minimize the use of design resources, at the same time, it is best to just using a set of DPI image resources? The
must first clear the concept of self-rendering, the Android SDK will be the active screen size to select the appropriate resource file for rendering. If the SDK detects that your phone dpi is 160, it will take precedence to the DRAWABLE-MDPI directory to find the appropriate image resources, attention is only a priority. Suppose your phone dpi is 160, but you only have the corresponding picture resource file in the Xhpdi directory. program to perform as normal.

So in theory, just need to provide a specification of the picture resources is OK, assuming only to provide ldpi specifications of the picture. For large-resolution phones, it is not clear to enlarge the image, so you need to provide a picture of the maximum dpi you need to support. This way, even if the user's mobile phone resolution is very small, so the picture shrinking is still very clear.
XHDPI become the first choice
Above said that only need to provide a large set of DPI picture is OK, now the market resolution of the mobile phone can reach the maximum 1080x1920 resolution. such as NEXUS5. DPI belongs to xxhdpi, but after all, not yet popular, the most popular high-end machine in the market resolution is more concentrated in the 720x1080 range, that is, more concentrated in xhdpi. So now look at the XHPDI specifications of the picture became the first choice. Of course, with the improvement of technical specifications after the development, may later on the market xxdpi mobile phones will become more and more common.  But this is something. What about design resource constraints?
In today's app development, there are basically iOS and Android version numbers. Some companies are interacting with each other in order to keep the app's different version number experience. Other companies may be more nervous about designing resources. In these cases the iOS and Android version numbers are basically a designer-led, and in most cases the designer may be more likely to design on the iphone, including late-transduction and the like. At this time as an Android developer, do you also require the designer to separate a set of image resources for Android? It's going to ruin your designers. Here's a great way to tell a project.
It is believed that designers will generally use the latest IPhone5 (5s and 5 size and resolution are the same) to do the prototype design, and iPhone5 screen resolution of 640x1164, screen size of 4 inches. According to the Pythagorean theorem (a^2 + b^2 = c^2) 640^2+1164^2=1764496, then its source, can get screen diagonal, resolution: 1328, divided by 4 can be derived iphone5 dpi:1328/4≈332 If you can see the iPhone5 screen dpi is about equal to 320, only belongs to xhdpi, so you say there is no dedicated for designers, you can be very proud of Android end cut graph, direct to iphone a cut image resources into the drawable-xhdpi directory OK that.


Android Common resolutions (MDPI, HDPI, xhdpi, xxhdpi) screen adjustments

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.