Android Layout Size Thinking

Source: Internet
Author: User

First, preliminary thinking
    1. Although the Android display adaptation of the scheme is a bit strange, initially it is not easy to understand immediately, but this program does have its own truth, the whole idea is clear, the plan is complete, no mishap
    2. The "screen density scaling mechanism" used by Android, which corresponds to the Web front end, is the "screen scale reduction mechanism"
    3. Android side, each section of the DP ending value represents a real physical size, yes, is the physical size, you can even think of its unit is "centimeter"!
    4. What else can I use besides the percentages and physical dimensions? You can use PX, yes, pixels, this is the most primitive, but what are the problems with this?
    5. The use of DP and different layout is logically adaptable to all situations
second, in-depth thinkingFrom the source,
  1. Layout display units at the beginning of the most direct thinking must be the PX, because the electronic screen is composed of px pixels, so you define the length of a component will naturally use the PX
  2. However, after you use PX, you will naturally encounter a problem: when the screen changes, can you show the effect you expect?
  3. This problem is very tricky, the beginning to get will not find a breakthrough, because the screen strange, and then the actual use of the scene is different, how may have silver bullets, but wait, we calm down the heart analysis
  4. think about it, the screen changes can only have two dimensions: screen physical size and screen pixels, and analysis of a few practical examples can be found that we actually only care about one of them, that is the physical size, and in fact, the use of the scene can be properly separated out, and finally filtered out the five cases
    1. "1" When the physical size of the screen does not change, regardless of the screen pixels, we hope that the display effect is the same as the
      1. because it is from the human eye of the situation to consider, the human eye is based on the physical size, so this basic is a fixed value
    2. and When the physical size of the screen is reduced, there will be a more complicated situation, but there are a few general rules:
      1. "2" when the narrow ground is not much, we basically want to show the content is not changed, the display of the things scaled down some
      2. "3" when the more narrow, we hope Look less content (in fact, the layout changes, how the change is related to the specific scene)
    3. and when the screen physical size is enlarged, the same:
      1. "4" when the magnification is not much, we basically want to display the content unchanged, the display of the Something to zoom in on some
      2. "5" when zoomed in more, we want to show more content (in fact, the layout changes, how the change is related to the specific scene)
  5. Compare the three layout size mechanisms
    1. Px
      1. None of these five can be achieved.
    2. Dp
      1. The first one can be perfectly fulfilled
      2. The second and fourth are achieved through several special dimensions (matchparent, proportional layout)
      3. The third and fifth can only be done by the above special dimensions, but cannot be achieved
    3. Percentage
      1. The first one can be perfectly fulfilled
      2. The second and fourth can be perfectly fulfilled.
      3. Third and fifth cannot be achieved
    4. dp+ Physical Dimension Special treatment mechanism (that is, Layou-large folder)
      1. The third and the most perfect realization
    5. Percent + physical size special treatment mechanism
      1. The third, the fifth perfect realization
  6. So overall, the percent layout has a little advantage over the DP layout, with limited advantages
third, other small things 3.1.DP LayoutAnd then, specifically, how the DP layout implements the first one.
  1. This is a two-piece, a piece of dimension, a picture
  2. first for the dimensions of the dimension, this does not you Tube, you directly labeled DP, no more tube, it will be a physical size, not with the change in pixel density
    1. and here this DP and PX conversion is a strict formula, very accurate, is not very good calculation:
        px = dp*ppi/160
      1. dp = PX/(PPI/ 160)
      2. PPI = (√ (length pixels ²+ width pixels ²)/Screen Diagonal Inches
    2. from here, you can see that the so-called ÷3 is actually just 3, or 2.9, 3.2 or something.
  3. Then for the picture, according to the "original image of the screen density" to classify the picture in different folders to achieve (note with the physical size special treatment mechanism to distinguish)
    1. It needs to be said here that there are some small circles around
    2. First, a picture to you, is you manually decide which folder to put the diagram (there are low--medium--high--xhigh--xxhigh several folders)
      1. You're based on the screen density of the target screen for the person who made this picture.
      2. Based on the calculated screen density, select a folder according to Google's criteria (standard screen density value per folder)
    3. Then the system will zoom in so
      1. First, the system will recognize how dense your screen is.
      2. And then divide your screen density to what level is this standard? 】
      3. Then go to the folder under the corresponding level to find the picture
      4. If the current folder does not have pictures, go to the front and back (after the main), found, according to the standard ratio to scale (3:4:6:8:12)
      5. So whatever you do, the system is only responsible for scaling, you also know how to put the consequences, so you decide how to put it (so you will have a range, that is, medium points)
    4. This scaling is obviously problematic when the target resolution is not the standard resolution and is inaccurate
      1. For example, if your goal is 170, then you can only put in 160 of the folder, and then if you take a 170 mobile phone to run, you will find the picture is significantly reduced
    5. Comments:
      1. Problems with picture shrinking unless you can customize the screen density folder
      2. If it is not customizable, the size of the ImageView can be fixed by size and then shrunk with the center of the minimum edge of SRC
How does a 3.2.UI pixel chart compare to a phone run?
    1. All corresponding target dimensions are proportional to the model.
      1. The original is PX figure A
      2. If the target size is 5.5, then run down with 5.5 and run down with the 4.7. C
      3. If the target size is 4.7, then run down with 4.7 and run down with the 5.5.
      4. A, B, D proportional adaptation
      5. C and E are not proportional to the above.

      

Bo friends Mid-Autumn Happy ~

Android Layout Size Thinking

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.