Talking about how android can adapt to both pad and mobile phone, and talking about how android can adapt to pad at the same time

Source: Internet
Author: User

Talking about how android can adapt to both pad and mobile phone, and talking about how android can adapt to pad at the same time

Precautions and skills

Some time ago, the company wanted to create an android app and adapt it to pad and mobile phones. At first, I thought this was impossible, because the apps we saw on the market all wanted two versions, mobile and pad. Because the size difference between the mobile phone and the screen is too large, it is generally not said that an app is compatible with both versions.

In order to achieve screen compatibility, I went to the Internet to find information and see what the current mainstream mobile phone sizes and resolutions are. Shows the main information:

The resolution of the pad produced by each manufacturer is the same as that of the mobile phone. Therefore, you can finish the adaptation of the mobile phone page before considering the page adaptation of the pad.

After examining the screen resolution and size distribution of mainstream mobile phones, we have to consider another focus in android adaptation, that is, the screen ppi value. The so-called screen ppi value is: pixels Per Inch indicates the number of Pixels Per Inch. By default, the android system divides the screen into five levels: idpi, mdpi, hdpi, xhdpi, and xxhdpi Based on the screen resolution. Each level corresponds to the corresponding ppi value, shows the corresponding relationship:

Generally, the artist generates a set of cut charts (the resolution recommended for the cut chart is 480x800, so it is much easier to adapt to the page on the Internet, and the conversion rate of px and dp is exactly) and the size chart (anyway, the artist I met didn't have a set of different resolutions, so the workload is indeed large), and when it comes to the size chart, the scale of the artist above the mark is generally in px units, in the android layout, we often use dp and sp. In this way, we have to convert px and dp. For details about the conversion rules, see the conversion rules of px and dp.

Precautions and skills in coding

The above describes some preparations and precautions for page adaptation. Next, let's talk about some precautions and skills for page adaptation in encoding. 1. In the xml layout, try to use weight Values for balanced distribution, and use less fixed values to define the container or control size. Fill_parent is recommended for containers. If the control or container cannot use a fixed value, use a fixed value. Generally, mobile phones do not look like this. If a sample is displayed, you must go to values, values-ldpi, values-mdpi, values-hdpi, and values-xhdpi, define a variable in the diamen file of the folder based on the corresponding screen resolution and reference it in the layout file,


In this way, the screen with different resolutions can be adapted.

Compatible with mobile phones and pad adaptation

Because the cell phone will be relatively small, it will be distorted if the pad is referenced. So you have to find another pad cut and size chart. Now there are two sets of cropping images. After experiments, we found that the android system uses the minimum screen width to distinguish between mobile phones and tablets, when the minimum screen width is greater than or equal to 600px, the device is regarded as a pad. When the minimum screen width is less than 600px, the device is regarded as a mobile phone. So you can define two types of drawable folders, one is the drawable-sw600dp-hdpi (this is used to put the pad version of the cut ), the other is drawable-xhdpi (this is a cut chart for mobile phones ). The value folder is similar, values-sw600dp (this is put pad version of diamen files) values (this is put mobile version of diamen files ).

If you do not know the minimum screen width of your mobile phone, run the following code on your mobile 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 la s can get the minimum width of the screen in the code and then fine-tune it.
 

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.