Length units in Android, detailed

Source: Internet
Author: User

First, introduce the DP and SP.

DP is also dip. This is basically similar to SP. You can use a DP or SP if you set properties that represent length, height, and so on. However, if you set the font, you need to use the SP.

The DP is not density-independent, and the SP is not related to scale, except for density. If the screen density is 160, then the DP and SP and PX are the same.

1dp=1sp=1px

Second, introduce the PX

But if you use PX as the unit, if the screen size is the same (assuming 3.2 inches), the screen density becomes 320.

So the original width of the TextView is set to 160px, in the density of 320 of the 3.2-inch screen is more than the density of 160 of the 3.2-inch screen to see the half-short.

But if it is set to 160DP or 160SP. The Width property value is automatically set to 320px. That means 160 * 320/160.

320/160 of these are called density scale factors. that is, if you use the DP and SP, the system will automatically convert based on the change in screen density. Let's see what other units mean. PX: Represents the actual pixel of the screen.

For example, the 320*480 screen has 320 pixels in the landscape and 480 pixels in the portrait. In: represents inches, which is the physical size of the screen. Equal to 2.54 centimeters per inch.

For example, describe the size of a mobile phone screen, often said, 3.2 (English), 3.5 (English), 4 (English) inch refers to this unit.

These dimensions are the diagonal length of the screen. If the phone's screen is 3.2 inches, it indicates the phone's screen (viewable area)

The diagonal length is 3.2*2.54 = 8.128 centimeters. Readers can measure their own phone screen to see if the actual size is the same.


welcome everyone to join my QQ group: 454430053

Length units in Android, detailed

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.