Adaptive Multi-resolution solution for Android applications
1. First, create multiple layout folders (drawable as well).
Create multiple layout folders under the Res directory, the folder name is layout-800x480, and so on. What you need to adapt to that resolution.
Attention:
A. The larger number should be written in front: such as layout-854x480 and not write layout-480x854.
B. Two digits are preceded by a lowercase letter x, not multiplication sign.
2. Adjust the layout width and other settings under the layout. To accommodate different resolutions.
3 finally need to add the following paragraph inside the androidmanifest.xml, without this paragraph adaptive can not be achieved:
</Application> <supports-screensandroid:largescreens= "true" Android: Normalscreens= "true"= "true"/></manifest
Add the above code between the </application> tab and the </manifest> tag. Can
====================================================== Android App Adaptive screen size and layout one: different layout
Android phone screen size is different, there are 480x320, 640x360, 800x480. How can I get the app to adapt to various screens automatically? In fact, it is very simple to create a different layout folder in the Res directory, such as layout-640x360,layout-800x480, where all the layout files are compiled
will be written to R.java, and the system uses the appropriate layout according to the size of the screen.
II: HDPI, MDPI, ldpi
In the previous version, there was only one drawable, while the 2.1 version had drawable-mdpi, drawable-ldpi, drawable-hdpi Three, and the three were mainly for
Multi-resolution.
The difference between drawable-hdpi, drawable-mdpi and drawable-ldpi:
(1) drawable-hdpi contains high-resolution images, such as WVGA (480x800), FWVGA (480x854)
(2) drawable-mdpi contains medium-resolution images, such as HVGA (320x480)
(3) drawable-ldpi contains low-resolution images, such as QVGA (240x320)
The system will be based on the resolution of the machine to each of these folders to find the corresponding picture.
Correction: should be a picture of different density
In developing the program in order to be compatible with different screens on different platforms, it is recommended that the respective folders store different versions of the images according to requirements.
Note: The resolution of the three is not the same, as you put the computer's resolution, the picture will become larger, the opposite resolution high, the picture shrinks. Screen Orientation:
Horizontal screen vertical screen automatically switch:
The Res directory can be set up in the layout-port-800x600 and Layout-land two directories, which are placed in the vertical screen and horizontal screen two layout files, so that the mobile phone screen
When the screen direction changes, the system will automatically call the corresponding layout file, to avoid a layout file can not meet the two screen display problems.
Different resolution horizontal screen vertical screen automatically switch:
Using 800x600 as an example you can build layout-port-800x600 and layout-land-800x600 two directories in the Res directory
Do not switch:
The following steps are circulated online, but I myself was through a graphical interface to achieve this configuration, is the same as the same, I will be free to paste the picture.
Also note that each activity has this attribute screenorientation, each activity needs to be set, can be set to vertical screen (portrait), or can
Set to No gravity sensing (nosensor).
To allow the program interface to maintain a direction, do not follow the direction of the mobile phone to change the way: in the androidmanifest.xml to configure a bit. Join this line
android:screenorientation= "Landscape". For example (landscape is landscape, Portrait is portrait):
<?XML version= "1.0" encoding= "Utf-8"?><ManifestXmlns:android= "Http://schemas.android.com/apk/res/android"Package= "Com.ray.linkit"Android:versioncode= "1"Android:versionname= "1.0"><ApplicationAndroid:icon= "@drawable/icon"Android:label= "@string/app_name"><ActivityAndroid:name=". Main "Android:label= "@string/app_name"Android:screenorientation= "Portrait"><Intent-filter><ActionAndroid:name= "Android.intent.action.MAIN"/><CategoryAndroid:name= "Android.intent.category.LAUNCHER"/></Intent-filter></Activity><ActivityAndroid:name=". GamePlay "Android:screenorientation= "Portrait"></Activity> <activity Span style= "color: #ff0000;" >android:name= ". Optionview " Android:screenorientation=" Portrait " Span style= "color: #0000ff;" >></activity> </application> <uses-sdk android: Minsdkversion= "3" /> </manifest>
In addition, the switch of each screen in Android will restart activity, so you should save the current active state before the activity is destroyed, when the activity is re-create
When loading the configuration, the in-progress game will not restart automatically!
Some programs are suitable to switch from vertical screen to horizontal screen, or vice versa, how to do this time? The following configuration can be performed where the activity is configured
Android:screenorientation= "Portrait". This will ensure that the vertical screen is always vertical, or landscape landscape.
And some programs are suitable for the screen switch. How to deal with it? The first thing to do when configuring activity is to configure the following:
Android:configchanges= "Keyboardhidden|orientation", in addition, the Onconfigurationchanged method to rewrite the activity. Here's how it's implemented
, there is no need to do too much content:
@OverridePublicvoid onconfigurationchanged (Configuration newconfig) {super.onconfigurationchanged (Newconfig); if ( this.getresources (). GetConfiguration (). Orientation = = Configuration.orientation_landscape) {// land does nothing is OK} else if ( This.getresources (). GetConfiguration (). Orientation == Configuration.orientation_ PORTRAIT) {// port does nothing is OK } }
Write a support multi-resolution program, based on 1.6 development, set up three resource folders drawable-hdpi drawable-mdpi drawable-ldpi, which are stored separately
72*72 48*48 36*36 's icon file. When I test on G1 (1.5 system), the icon should be adaptive to 48*48, but the actual display is 36*36.
How can you make it adaptive to the 48*48 icon?
Workaround: drawable-hdpi drawable-mdpi drawable-ldpi changed to drawable-480x320 drawable-800x480 Multi-resolution supported folder
Android App Adaptive screen size (reprint)