Talking about how Android fits both pad and mobile

Source: Internet
Author: User

Previous precautions and Tips

Some time ago the company to do an Android app, but also to adapt to the pad and mobile phone. At first I thought it was impossible to achieve, because the app we saw on the market was two versions, mobile and pad, respectively. Because the size of the phone and screen is too different, it is generally not said that an app is compatible with two versions.

in order to achieve screen compatibility, so I specifically go to the Internet to find information, to see the current market on the mainstream mobile phone size and resolution of the number of respectively. The main things to find are as follows:

and pad words each manufacturer's pad resolution will be the same as the mobile phone, so you can finish the mobile phone page adaptation and then consider the pad page adaptation.

After examining the current distribution of screen resolution and size of mainstream mobile phones, it is important to consider another focus of Android adaptation, that is, the PPI value of the screen, the so-called PPI value of the screen is:Pixels per inch represents the number of pixels (Pixel) that are owned by inches. The Android system, by default, divides the screen into five levels of idpi, MDPI, hdpi, xhdpi, and xxhdpi based on the resolution of the screen, and each level corresponds to the corresponding PPI value, as shown in the corresponding relationship:

art generally will be a set of transduction (Transduction recommended resolution is 480x800, so that the compatibility of the online page adaptation is much easier, PX and DP conversion magnification is just 1:1) and the size map (anyway, I encountered the artist does not have each resolution to a set, This is really a lot of work, and when it comes to dimensional drawings, the artwork is usually measured in px, whereas in the Android layout we often use DP and SP. So we have to convert the PX and DP, the specific conversion rules can be seen here: PX and DP conversion rules.

Considerations and tricks in coding

It says some of the previous preparations and considerations for some of the page adaptations, so let's talk about some of the pages in the code that are appropriate for you. Considerations and Tips . 1, in the XML layout, try to use weight value to balance the distribution, as far as possible to use a fixed value to define the size of the container or control. Containers are recommended for values such as Fill_parent. If the control or container is not able to use a fixed value, then use a fixed value. Ordinary mobile phones are not distorted. If there is a aliasing, you have toValues,values-ldpi,values-mdpi,values-hdpi,values-xhdpi, according to the different screen resolution and then in the folder's Diamen file to define a variable and then in the layout file inside the reference,


This way you can adapt the screen to a different resolution.

Compatible with the pad after the phone

Since the phone cut chart will be relatively small, if the pad refers to the words will be distorted. So we have to find another pad version of the transduction and size map. Now there are two sets of graphs, after the experiment found that the Android system is based on the minimum screen width to differentiate the phone or pad, when the minimum screen width >=600px as the device as a pad, when the screen minimum width < 600px is considered a mobile phone. So you can define two types of drawable folders, one is drawable-sw600dp-hdpi (this is used to put the pad version of the cut), and the other is drawable-xhdpi (this is used to put mobile phone version of the cut). And the value folder is similar, VALUES-SW600DP (this is the pad version of the Diamen and other files) values (this is the mobile version of the Diamen and other files).

If you don't know the minimum screen width of your phone, you can use the following code to view it on your phone:

<pre name= "code" class= "java" ><span style= "font-size:18px;" >configuration config = getresources (). GetConfiguration ();        int  smallestscreenwidth = config.smallestscreenwidthdp;</span>
<span style= "FONT-SIZE:18PX;" ></span>
Sometimes, some layouts are just a little bit biased in some resolutions, so you can get the minimum screen width in your code and fine-tune it.

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

Talking about how Android fits both pad and mobile

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.