At first, I developed the simulator selected as WVGA854, with a resolution of 854*480. I developed after the 800*480 on the phone when the feeling is OK, but to 480*320, and 320*240 resolution on the phone, a lot of the interface is distorted, then I feel the importance of self-adaptation of the app.
There are two major problems with self-adaptation: horizontal screen and vertical screen switching, and the resolution size is different.
First, when the horizontal screen switch to vertical screen, the solution:
In the Res directory, the establishment of Layout-port and Layout-land two directories, respectively, a vertical screen and horizontal screen two layout files, when the mobile phone screen direction changes when the Android system will automatically call the corresponding layout file.
Of course, there is no way to switch. Either a horizontal screen or a vertical screen. Can be set in the Androidmanifest.xml file, such as an activity set to android:screenorientation= "portrait" so that the vertical screen is maintained, if set to
android:screenorientation= "Landscape" This keeps the horizontal screen.
Two. When we encounter different resolution sizes, we also encounter three problems: Image size, layout, horizontal screen and vertical screen switching.
Picture problem to solve, to android2.0 after the API, we will find that the original Drawable folder into 3 are drawable-hdpi, drawable-mdpi, drawable-ldpi.
The first folder puts pictures of high-resolution phones, such as: 854*480, 800*480
The second file folder puts in the image of the resolution phone, for example: 480*320
The third folder is a picture of a low-resolution phone, such as: 320*240
About layout and horizontal screen switch to vertical screen similar, also only need to create a different layout folder in the Res directory, such as layout-480x320,layout-800x480, the system will be based on the size of the screen to choose the appropriate layout to use.
Layout is a layouts folder for high resolution vertical screens
Layout-land is a layout folder that fits high resolution horizontal screens
layout-land-320x240 is a layout folder that fits a low resolution horizontal screen
layout-land-480x320 is a layout folder adapted to the horizontal resolution of the screen
layout-port-320x240 is a layout folder for a low resolution vertical screen
layout-port-480x320 is a layout folder adapted to the vertical screen resolution
This makes the layout file suitable for the finished.
I personally think that the high-resolution simulator to develop the effect is better, and then to do the various resolutions of the adaptation. Sometimes when we layout, low-resolution layouts may need to be modified.
[Mw_shl_code=java,true] Finally, there's another question. What if I write a dead layout in a Java program?
This is very annoying, you need to determine the size of the screen, the code to get the screen size is as follows:
WindowManager WindowManager = Getwindowmanager ();
Display display = Windowmanager.getdefaultdisplay ();
int screenwidth = Display.getwidth ();
int screenheight = Display.getheight (); [/mw_shl_code] [Mw_shl_code=java,true] The following code fragment is my own in the program to write dead layout used, for reference only:
Button cancelbtn = New button (this);
if (screenwidth<320 | | screenheight<320)
Cancelbtn.setlayoutparams (New Layoutparams (60,
Android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
else if (screenwidth <480 &&screenheight = = 480)
Cancelbtn.setlayoutparams (New Layoutparams (80,
Android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
else if (screenwidth >480 && screenheight = = 480)
Cancelbtn.setlayoutparams (New Layoutparams (160,
Android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
Else
Cancelbtn.setlayoutparams (New Layoutparams (120,
Android.view.ViewGroup.LayoutParams.WRAP_CONTENT)); [/mw_shl_code]