Android Visual spec-spacing specification and text spec unit conversion (DIP, SP, px)

Source: Internet
Author: User

http://blog.csdn.net/shimiso/article/details/29826073

1, Dip and px

When the Android engineer writes the page, the margin value is in dip, and the visual designer usually controls the margin value through the PX, what is the difference between different units? Look at the following parameters.

Visual measurement results between dip and PX under WVGA (800x480):

1dip=2px

9dip=14px

17dip=26px

2dip=3px

10dip=15px

18dip=27px

3dip=5px

11dip=17px

19dip=29px

4dip=6px

12dip=18px

20dip=30px

5dip=8px

13dip=20px

21dip=31px

6dip=9px

14dip=21px

7dip=11px

15dip=23px

8dip=12px

16dip=24px

According to the above values can be obtained in a WVGA dip and PX Conversion formula (2N for any even, 2n-1 represents the small and even 1 odd):

Conversion formula between dip and PX:

A. 2N + 2N/2 = PX

B. (2n-1) + 2N/2 = PX

Note: An even value dip is 1.5 times times equal to the corresponding PX value, and the spacing between the even values and the odd element setting is centered with the 1px error, which may not be very aesthetically pleasing to look at (e.g.).

A and B center align with a value difference, and C and D can be perfectly aligned.

However, the probability of this situation is very small, only in the narrow page of the time common to meet when the emergency treatment can also solve the problem, but if the design at the beginning of attention, the back of the narrow buckle will not be the problem, but also eliminate the emergency treatment time, to a certain extent can improve efficiency.

Visual measurement results between dip and PX under HVGA (320x480):

1dip=1px

9dip=9px

17dip=17px

2dip=2px

10dip=10px

18dip=18px

3dip=3px

11dip=11px

19dip=19px

4dip=4px

12dip=12px

20dip=20px

5dip=5px

13dip=13px

21dip=21px

6dip=6px

14dip=14px

7dip=7px

15dip=15px

8dip=8px

16dip=16px

The result of the above parameter is that the dip is equal to the PX value.

From the above, the visual designer in the WVGA (480x800) mode design, the recommended optimal spacing is: 12px, 18px, 24px, 30px, 36px, 42px, 48px, because the dip, PX value in the HVGA\WVGA corresponding are even, Each element can be the most stringent alignment.

Second, SP and px

Visual measurement results between SP and px under WVGA (800x480):

7sp=11px

15sp=23px

23sp=35px

8sp=12px

16sp=24px

24sp=36px

9sp=14px

17sp=26px

25sp=38px

10sp=15px

18sp=27px

26sp=39px

11sp=17px

19sp=29px

27sp=41px

12sp=18px

20sp=30px

28sp=42px

13sp=20px

21sp=31px

29sp=44px

14sp=21px

22sp=33px

30sp=45px

The results obtained from the above parameters are as follows:

The conversion formula between SP and PX is the same as the conversion formula for dip and PX:

A. 2N + 2N/2 = PX

B. (2n-1) + 2N/2 = PX

Results of conversion between SP and px under HVGA (320x480):

7sp=7px

15sp=15px

23sp=23px

8sp=8px

16sp=16px

24sp=24px

9sp=9px

17sp=17px

25sp=25px

10sp=10px

18sp=18px

26sp=26px

11sp=11px

19sp=19px

27sp=27px

12sp=12px

20sp=20px

28sp=28px

13sp=13px

21sp=21px

29sp=29px

14sp=14px

22sp=22px

30sp=30px

The result of the above parameter is that the SP value is equal to the PX value.

From the above, the visual designer in the WVGA (480x800) mode design, the recommended commonly used best font size is: 18px, 24px, 30px, 36px, 42px, in some need to strictly align the position, these parameters of the text is not a problem, of course, the other font size is also available, After all, not all of the text in the app needs to be strictly aligned.

Knowledge Popularization:

SP, dip,android default units, can be adapted to different screen sizes, the same font size, different screen sizes display different visual effects.

PX is a fixed pixel value and does not actively adapt to the screen size, and the visual effect is the same as the screen size.

Android Visual spec-spacing specification and text spec unit conversion (DIP, SP, px)

Related Article

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.