Android Notes (ix) dimensions and units

Source: Internet
Author: User

1 Android introduced a new set of unit DP and SP.
DP is the meaning of the density-independent pixels, also known as dip, and the ratio of its display in different density screens will be consistent compared to PX.
The SP is the meaning of the scalable pixel, it adopts the same design concept as DP, solves the problem of the adaptation of the text size.

2. What does density mean? The density in Android is the number of pixels per inch of the screen, usually in DPI. For example, a mobile phone screen width is 2 inches long is 3 inches, if its resolution is 320*480 pixels, then the density of this screen is 160dpi, if its resolution is 640*960, then this screen density is 320dpi, so the higher the density value of the screen display more fine effect.
According to Android rules, on the 160dpi screen, 1DP equals 1px, and on the 320dpi screen, 1DP equals 2px. Therefore, using DP to specify the width and height of the control ensures that the controls are displayed in a consistent scale across the screens of different densities.

3. When writing an Android program, try to specify the size of the control or layout as match_parent or wrap_content, if you have to specify a fixed value, use the DP as the unit, specify the text size using the SP as the unit.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Notes (ix) dimensions and units

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.