Android Application adaptive screen size

Source: Internet
Author: User

Android Application adaptive multi-resolution Solution
1. Create multiple layout folders (the same is true for drawable ).

Create multiple layout folders under the res directory, and the folder name is layout-800x480. To adapt to that resolution, write it as anything.

Note:

A. Large numbers should be written in front: such as layout-854x480 rather than layout-480x854.

B. The two digits are preceded by the lowercase letter X, rather than the multiplication number.

2. Adjust the length and width of layout and other settings under layout. To adapt to different resolutions.

3. Add the following section in androidmanifest. XML, which cannot be implemented without self-adaptation:

</application>    <supports-screensandroid:largeScreens="true"     android:normalScreens="true"  android:anyDensity = "true"/></manifest> 

Add the above Code between the </Application> label and the </manifest> label. You can.

========================================================== ====================
Android Application adaptive screen size and layout Layout
I. Different Layout

The screen sizes of Android mobile phones vary by 480X320,640x360,800 X. How can an app automatically adapt to different screens?
In fact it is very simple, just need to create different layout folder under the res directory, such as layout-640x360, layout-800x480, all the layout files in the compilation

Then, it will be written into R. Java, and the system will select the appropriate layout based on the screen size for use.

Ii. hdpi, mdpi, and ldpi

In earlier versions, there was only one drawable, while in version 2.1, there were three types: drawable-mdpi, drawable-ldpi, and drawable-hdpi.

Supports multiple resolutions.

Differences between drawable-hdpi, drawable-mdpi, and drawable-ldpi:

(1) The drawable-hdpi contains high-resolution images, such as WVGA (480x800) and fwvga (480X854)

(2) drawable-mdpi stores medium-resolution images, such as hvga (320x480)

(3) drawable-ldpi stores low-resolution images, such as qvga (240x320)

The system will find the corresponding images in these folders according to the machine resolution.

Correction: it should be an image corresponding to different density

To be compatible with different screens on different platforms, we recommend that you store images of different versions in different folders as needed.

Note: the resolution of the three items is different. Just as you lower the resolution of your computer, the image will become larger. On the contrary, the resolution will be high and the image will be reduced.
Screen direction:

Automatic switching of landscape and portrait screens:

You can create two directories: layout-port-800x600 and layout-land under the res directory, which are placed in the vertical and horizontal layout files, so that the mobile phone screen

When the screen direction changes, the system automatically calls the corresponding layout file to avoid the problem that one layout file cannot meet the needs of the two screen display methods.

Automatic switching of landscape and portrait screens with different resolutions:

Take 800x600 as an Example
Two directories of layout-port-800x600 and layout-land-800x600 can be created under the res directory

Do not switch:

The following steps are circulated on the Internet, but I used to implement this configuration through a graphical interface, which is the same in different ways. I will paste the image when I have time.

Note: Each activity has the screenorientation attribute, which must be set for each activity. You can set this attribute to portrait or

Set to nosensor ).

Solution to keep the program interface in one direction and not change with the orientation of the mobile phone:

Configure androidmanifest. xml. Add this line

Android: screenorientation = "Landscape ".
For example, (landscape is horizontal and portrait is vertical ):

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"       package="com.ray.linkit"       android:versionCode="1"       android:versionName="1.0">     <application android:icon="@drawable/icon" android:label="@string/app_name">         <activity android:name=".Main"                   android:label="@string/app_name"                   android:screenOrientation="portrait">             <intent-filter>                 <action android:name="android.intent.action.MAIN" />                 <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>         </activity>                 <activity android:name=".GamePlay"                 android:screenOrientation="portrait"></activity>                 <activity android:name=".OptionView"                 android:screenOrientation="portrait"></activity>     </application>     <uses-sdk android:minSdkVersion="3" /> </manifest>  

In addition, the activity is restarted every time the screen is switched on in Android. Therefore, the status of the current activity should be saved before the activity is destroyed. When the activity is created again

When the configuration is loaded, the game in progress will not be restarted automatically!

Some programs are suitable for switching from a portrait screen to a landscape screen, or vice versa. What should we do at this time? You can configure the activity as follows:

Android: screenorientation = "portrait ". In this way, you can ensure that the portrait screen is always portrait or landscape.

Some programs are suitable for switching between landscape and landscape screens. What should we do? Configure the activity as follows:

Android: configchanges = "keyboardhidden | orientation". In addition, you need to override the onconfigurationchanged method of the activity. The implementation method is as follows:

, You do not need to do too much content:

@Override         public void onConfigurationChanged(Configuration newConfig) {                 super.onConfigurationChanged(newConfig);                 if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {                         // land do nothing is ok                 } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {                         // port do nothing is ok                 }         } 

Write a program that supports multi-resolution, developed based on 1.6, and creates three resource folders drawable-hdpi drawable-mdpi drawable-ldpi, which are respectively stored in

72*72 48*48 36*36 Icon files. When I test on G1 (1.5 of the system), the icon should be adaptive to 48*48, but the actual display is 36*36.

How can we make it adapt to the 48*48 icon?

Work und: drawable-hdpi drawable-mdpi drawable-ldpi changed to the multi-resolution supported folder for the drawable-480X320 drawable-800X480

 

Turn: http://www.eoeandroid.com/thread-160023-1-1.html

 

 

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.