Previous precautions and Tips
A time ago the company wanted to do an Android app. At the same time to adapt to the pad and mobile phone. Just started to think that this is impossible to achieve, because we see in the market app are two version number, respectively, mobile and pad version.
Because the size of the phone and screen is too large, it is generally not said that an app is compatible with two version numbers at the same time.
in order to achieve screen compatibility, so I specifically to find information on the Internet. Look at the size and resolution of the mainstream phones in the market today. The main found situation is for example with what is seen:
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.
The current distribution of screen resolution and size of the mainstream mobile phone is examined. Consider another focus of Android adaptation. Is the PPI value of the screen. The PPI value of the so-called screen is: Pixels per inchrepresents the number of pixels (Pixel) owned by the inches. The Android system, by default, will divide the screen into five levels of idpi, MDPI, hdpi, xhdpi, xxhdpi According to the resolution of the screen, each of which corresponds to the corresponding PPI value, as seen in the corresponding relationship:
art generally will be a set of transduction (Transduction recommended resolution is 480x800, so that the online page to adapt to the compatibility of easy very much. The conversion ratio of PX and DP is just 1:1) and the size drawing (anyway I encountered the artwork does not have a set of each resolution, so the workload is really large), and the size of the drawing. The size of the artwork in the above is generally in PX units, while in the Android layout we often use the units are DP and SP. So we have to convert the PX and DP, the detailed 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, as far as possible 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.
Suppose a control or container has no way to use a fixed value. Then use a fixed value.
Ordinary mobile phones are not distorted. Assuming that there is an aliasing, you have toValues,values-ldpi,values-mdpi,values-hdpi,values-xhdpi, a variable is then defined in the Diamen file of the directory and then referenced in the layout file, depending on the screen resolution ,
This way, the screen can be adapted to different resolutions.
Compatible with the pad after the phone
Because the cell phone cut chart will be relatively small, assuming that the pad reference will be distorted. So we have to find another pad version of the transduction and size map. Now there are two sets of cut charts. The experiment found that the Android system is based on the minimum screen width to differentiate the phone or pad, when the screen minimum width >=600px as the device as a pad, when the screen minimum width < 600px when the phone is considered to be. So can define two types of drawable directory, one is drawable-sw600dp-hdpi (this is used to put the pad version of the cut), there is a drawable-xhdpi (this is used to put mobile phone version of the cut). And the value directory 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).
Let's say you don't know that your phone's minimum screen width can be viewed on your phone with the following code:
Configuration config = getresources (). GetConfiguration (); int smallestscreenwidth = CONFIG.SMALLESTSCREENWIDTHDP;
</pre><span style= "font-size:18px" ><span style= "White-space:pre" ></span> sometimes, Some layouts simply have some resolution with a little deviation. You can get the minimum screen width in your code and fine-tune it. </span><pre>
Talk about how Android fits pad and mobile at the same time