The designer gave the PX unit callout, Android development in the end how many dip, DP, SP?

Source: Internet
Author: User

This article links http://blog.csdn.net/xiaodongrush/article/details/29560431

1. What do designers and developers agree on to develop an android APP?

First, choose a mainstream model.
Then, the designer based on the screen size of the model design, give the PX unit labeling.
Finally, according to the model, we can calculate the conversion method of PX and DP, and set the dimension of DP unit according to the dimensions of PX unit.
Note: 1DP=1DIP=1SP, for the general long-width DP or dip can be, SP is a font-specific units, in the operating system after setting large small font, you can change the SP display size.

This ensures that the designer's design is fully represented on this model. For other models, as long as the size difference is not very large, the display effect will not be too large. If it is on the mobile phone design, on the pad display, the difference will be relatively large.

2. Illustrative examples

Suppose Galaxynexus is selected as the target model for development.
The screen size of the model is 720x1280. The designer made the design on the 720x1280 canvas.
According to the calculation formula, learn the Galaxy Nexus above, 1dip=1dp=1sp=2px. So for the 40px annotation, development needs to give the 20DIP setting.

The conversion code is as follows, refer to from http://www.imyukin.com/?p=277

public static int dip2px (context context, float Dipvalue) {    final float scale = context.getresources (). Getdisplaymetrics (). density;    return (int) (Dipvalue * scale + 0.5f);} public static int Px2dip (context context, float Pxvalue) {    final float scale = context.getresources (). Getdisplaymetrics (). density;    return (int) (Pxvalue/scale + 0.5f);}
3. There is no way to ensure a complete fit between different devices

http://su1216.iteye.com/blog/1569029, this is good, only when mobile phone a screen density/cell phone b screen density = phone a screen width/phone b screen width, a mobile phone set on the DIP,SP,DP unit on the B phone To achieve equal to scale. This condition is too harsh, so it is impossible to have a perfect fit.

4. Can not be fully adapted, but also what to do

Since absolute lengths are not fully adaptable between different phones, the chance to use absolute lengths is reduced.

For example: A line only a very long button, do not use the length of the set button, because different phones, the button length shows a difference, some phones appear normal, on other phones may appear to be close to the side of the screen, even beyond the screen. It is best to set the button to Match_parent and set the left and right margins. The margins are the same on different phones.

5. UI adaptation to other things

This article is mainly about how to use the annotation conversion in the actual problem, UI adaptation there are many places to pay attention to. For example: components in the background of common 9-patch, linear layout and relative layout, a variety of density pictures drawable-hdpi, drawable-ldpi and drawable-mdpi and so on.

9-patch picture is to note the left and bottom of the black Line control zoom area, the right and the upper black line control content area, many people easily ignore the content area. The relative layout of the usage is still more, here does not expand. A variety of resolution pictures, generally no condition cut so many pictures, to drawable-hdpi also enough, more preparation of several test phones, see the effect is more important.

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.