Android programmers learn how to quickly master dp and px, androiddp

Source: Internet
Author: User

Android programmers learn how to quickly master dp and px, androiddp

I believe that many Android programmers have been coveted by the design sisters around me, so how can I win the favor of the design sisters? I just want to learn this article well.
When programmers and uidesigners discuss design drafts and cut diagrams, they often encounter unpleasant problems due to the dp and px issues. Here we can analyze two reasons:

1. The Conversion Relationship between dp and px is unknown. Including me and most of the development I have seen, I am not very concerned about how dp and px come from, and how to convert them. I only know how to use dp in general situations, the font size is sp, And the draw line is px.

2. Why is the design girl unable to mark dp, or even understand what dp is. Most companies do not create a design draft for Android, but only produce an iOS design draft. The iOS design draft is marked with px, and for the first reason above, android programmers cannot understand how much dp should be used to mark px.

Next we will use a simple way to enhance the feelings of programmers and design sisters!

First, we need to understand this figure:

This section lists the five common dpi types in Android development. dpi refers to pixels per inch (for example, a width is 1.5 inch pixels, the dpi of a mobile phone with a height of 2 inch or 320 pixels is: 240px/1.5in = 320px/2in = 160 dpi, which is the pixel per inch on the diagonal line). There is one less in the above table, it is LDPI, Which is 0.75 times that of MDPI, that is, 120 DPI.

The figure below shows the mainstream mobile phone screens corresponding to various dpi:

Calculate the screen dpi according to the formula below. In mdpi, dp/pixel = DPI/160, that is, 1 dip is equivalent to 1 pixel in a device with DPI 160. In xhdpi 320dpi, 1dp is equivalent to 2 pixels (again, it must be calculated using a calculator, and dpi is the pixel density on the diagonal line ).

Generally, xhdpi is designed to take care of iOS and Android. Since it is xhdpi, we can use 1dp = 2px to cope with the design girl's annotation. If it is not an xhdpi image, you can convert it according to the ratio of 0.75: 1: 1.5: 2: 3: 4.

I can help you here. The rest of the work depends on your practice.

Below are some common values:
Launcher icon: 48dp * 48dp
Action bar icons: 32dp * 32dp
Small icons: 16dp * 16dp
Notification icons: 24dp * 24dp
If you are not satisfied with these items, I will give you a picture. You are satisfied with the packet:

Content reference and network and Android.com
If it cannot be opened, please refer to "one of programmer's weapons VPN" here.

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.