Outline1, the folder in the Res directory in the Android screen size 2, the principle of the size of the DP representation 3, the 720p size of the adaptation needs to pay attention to what 4, UI transduction by what size to the best reference: http://www.360doc.com/content/12/ 0301/17/5087210_190881395.shtml
Several concepts:1) screen density (dpi): Dot per inch, which is the number of pixels each inch. LDPI (MDPI), hdpi (+), XHDPI (320) Calculation method: Take the 480x854,4.0inch phone as an example, its diagonal is 4.0inch, the diagonal pixel number is: (480^2 + 854^2) Open root = 979. so its dpi = 979/4 = 245, about 2402) screen size: diagonal length. Have Small,normal,large,extra large
3) Direction: Horizontal screen and vertical screen
4) Resolution: A total number of pixel points on a physical screen, such as 480x800. The concept of resolution is not used in our application, mainly DPI and size
5) DP (density-independent pixel) independent pixel unit. An abstract concept that is used to locate the UI layout, including size and position.
1, you can have four folders in the Android Engineering directory res, mainly to support the multi-resolutionImagedrawable-hdpidrawable-mdpidrawable-ldpidrawable-xhdpi
When the design gives the transduction, we first need to make it clear that the design given by the transduction is given in what size. If it is a 480x800 transduction, it should be placed in the drawable-hdpi directory, if it is 320x480 transduction, it should be placed in the MDPI directory. If it is a 720x1280 transduction, it should be placed in the XHDPI directory.
When you use the picture, the system looks for the picture according to the machine's resolution to the appropriate folder.
1: How does the system convert the resolution of a picture if only one set of pictures is placed? The Android system loads the image resources according to the following rules: First determine the phone's screen density, and then in the corresponding density folder to find the picture resources. If found, it is displayed. If it is not found, it will be looked up from drawable or other drawable-* folders. When found, the density represented by the folder is compared to the actual density of the phone, thereby scaling the picture. For example, find the resources under drawable (equivalent to from drawable-mdpi), and the phone is hdpi, so that when the image is displayed, Android will enlarge the image to meet the hdpi phone display needs. It is not difficult to imagine that the picture will become blurred.
The image is scaled before the system loads the picture, so the size you get through getwidth is already scaled. The ratio of scaling to density remains the same.
2: What's wrong with transduction misplaced folders? If the folder is misplaced, the system will scale accordingly, so that the image can be scaled incorrectly. For example, hdpi pictures in the MDPI, in the hdpi phone display, will be larger than the original picture
question 3:720p picture related questions?
Designed for Transduction, best based on that DPI? Is it all right? Generally should give 480*800 's hdpi of transduction. This will automatically shrink for mdpi. Image display quality is unaffected. For xdpi, the magnification is not large and the quality of image display is small.
So why not xhdpi, so it is not better to shrink the image? There are two reasons, one is to increase the size of the APK, the other is easy to cause the deformation of the cut graph, affecting the display. mainly for. 9 of the picture, there is a certain direction of compression, if set, the stretch area is too small, and then compression may deform. This is not absolute, of course, and can be achieved by increasing the stretch area of the. 9.png file. There may also be a reason why the XHPI model is not a majority.
2. DP Working principle
the most important thing to remember is a formula:Android calculates the pixel value first to determine the density of the screen. If we set MDPI to 1, then hdpi equals 1.5. If we use DP as the unit, Android will be converted to pixel according to the following formula:
PX = DP * density;
DP represents the independent pixel density, so-called independent, is not dependent on the density of the screen. In essence, DP actually represents the same physical length, note: Not in pixels, but in inch units. For example, MDPI, a screen with a length of M inch, has a number of pixels n1,dp to N2. For hdpi, the length is M inch and contains the number of pixels N1 * 1.5. According to the formula can be calculated, its DP value is n1 * 1.5/1.5 = N1. For the xhdpi is also N1.
that is, the same physical length has the same DP value.
from the surface, DP can represent an equal proportionThat is, in the screen densities of ldpi, MDPI, hdpi, and XDPI, the same DP value can be used to represent the same proportions.
Please note: It is proportional rather than size. Because the UI design, we are most concerned about the proportion of a view relative to the entire screen, for example: in MDPI, the length of a textview is 1/2 of the screen width, assuming that the width of the screen pixel is 320pixel, then TextView is 160pixel. And in hdpi, we need the TextView also accounted for 1/2 of the screen to be called to adapt to different screen density. To achieve this goal, Android provides the concept of DP.
We match the dip-mdpi screen to the DP one by one, which means that 1 pixel in the mdpi screen equals 1 dp. Typically, the screen width of the mdpi is 320pixel, so its screen width is 320DP.
Then in the hdpi screen, the width is usually 480pixel. Its 1/2 is 240pixel. If you use pixel, we need to use two values (mdpi:160px,hdpi:240px), and we can only enter 1 values. How to solve this problem?
The PX for MDPI,160DP corresponds to 160*1 = 160, which is half the screen width of 320px. For HDPI,160DP the corresponding px is 160*1.5 = 240px, also is half the screen width 480px. Thus, we use a value of: 160DP, which actually represents two pixels: 160px and 240DP.
Further analysis: Due to the same length (1inch), hdpi and mdpi pixel ratio is a fixed value (1.5), then hdpi and mdpi both intercept the same ratio (n/m), The ratio is still 1.5. At this point, we consider a pixel of mdpi as Unit 1, then HDPI is 1.5. That is, to represent the same scale, then the pixel ratio of hdpi and MDPI must be 1.5. Now, let the Android operating system record this ratio for us, and we'll use MDPI for unit 1. Number (re-create a unit: DP). When used, we write only the DP value, which is then automatically multiplied by the operating system. In this way, 1 DP representations of the values can represent a standard scale.
Simply put: In fact, DP represents a ratio. In Mdpi, 1DP represents 1/320, and 1DP in hdpi also represents 1/320. The use of density in the background by the Android operating system ensures that the same DP value can represent the same scale.
Note: The above statements are also limited. The DP representation must also have a premise that the size and density of the screen must meet the following conditions:mdpi:3.5inch,320*480, hdpi:4.0inch,480*800 or 480*854,xhdpi:4.5inch,720*1280. Even so, only mdpi and hdpi are guaranteed to have the same proportions, And the xhdpi can't. With full screen width as an example, both MDPI and hdpi are 320DP, and xhdpi is 360DP.
so since DP is only a special case to maintain the same proportion, then is the usefulness of the big discount?
keep in mind that Android screen adaptation is always relative, because the size is too large to fit completely, so we only fit the public, the largest number. Now the largest number is the above-mentioned size, the others are small audiences. Therefore, the UI design for the above screen can satisfy most of the phone's UI.
What about other sizes of mobile phones? We should remember this principle: use as few as possible to define the specific width of the DP.
Why is it width? Because of our common UI elements, the widths are not fixed. Height can be fixed. such as various button. We try to use DP to represent the interval, and use properties such as Fill_parent, wrap_parent, weight, and so on to make the UI autofill. What we need is an appropriate proportion, not the exact size.
Android screen Adaptation principle