android-screen Adaptation (i)

Source: Internet
Author: User

This article is based on the MU lesson network of Android video self-learning finishing, video address.

I. Important concepts related to screens 1. What is screen size, screen density, screen pixel density? A.

The screen size is the diagonal length of the phone screen.
Unit is inch, 1 inch = 2.54 cm

B.

The screen resolution is the number of pixels in the horizontal direction of the phone's screen.
Unit is px,1px = 1 pixel points
Generally with longitudinal pixel transverse pixels, such as 720

C.

Screen pixel density refers to the number of pixels per inch.
The unit is DPI, which is the abbreviation "dot per inch"
Screen pixel density is determined by the size of the screen and the resolution of the screen.
Calculation method: Take Huawei Glory 3c to calculate, screen size is 5 inch, resolution is 1280*720
Its pixel density = (1280^2 + 720^2) ^ (1/2)/5 = 293.7

2. What is DP, dip, SP, px? What's the relationship between them?

A. DP and DPI are one thing, name is different, in order to unify with SP, now use SP more. DPI has been explained above, there is no need to explain more.
B. PX is the smallest unit that makes up an image
C. SP is the unit of font size, an abstract pixel independent of scale. SP and DP very similar, the difference between units one is that the Android system allows users to customize the size of the text (small, normal, hit, oversized, etc.), when the text size is normal, 1sp=1dp=0.00626 inches, and when the text size is large or oversized, 1sp>1dp= 0.00625 inches.

3. What are mdpi, hdpi, xdpi, xxdpi? How to calculate and differentiate?

They all represent pixel densities.

name pixel density range
mdpi 120-160dpi
hdpi 160-240dpi
xhdpi 240-320dpi
xxdpi 320-480dpi
xxxdpi 480-640dpi
Two. How to fit the screen 1. Ways to support a variety of screen sizes

A. Using Wrap_content, match_parent, weight
Warp_content: Is the size of the fit content
Match_parent: Is full of the parent control
Weight: This property is a bit cumbersome and difficult to understand, let's take a look at it for example.

<!--I'm simply saying I'm not going to write it all.<linearlayout><buttonandroid:id="@+id/button1"android:layout_width="Match_ Parent "android:layout_height=" Wrap_content "android:layout_weight=" 1 " / >                 <buttonandroid:id="@+id/button2"android:layout_width=  "Match_parent"android:layout_height="Wrap_content"android:layout_weight ="2" />                 </linearlayout>

If you have the above layout, the actual length = layout setting length + remaining length *weight weight
The screen length is L, then the layout setting value of button1 and Button2 is l,button1 the remaining length is the length-button2 length of the total length l-button1, that is l-2l
L1 = L + (l-2l) * 1/3 = 2/3l
L2 = L + (l-2l) * 2/3 = 1/3l
This is calculated to find that the weight value we set is the opposite, so we are generally set to 0DP
That's what this is about.
L1 = L * 1/3 = 1/3l
L2 = L * 2/3 = 2/3l
B. Using a matching layout to disable absolute layout
C. Using Qualifiers-large
It is the same layout file that fits different sizes of screen sizes at the same time.
The main is to adapt to the plate.
D. Using an auto-stretch bitmap

2. Supports various screen densities 3. Implement an adaptive user interface process

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

android-screen Adaptation (i)

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.