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,
For example, an activity is set to android:screenorientation= "portrait" so that it keeps the vertical screen,
If set to android:screenorientation= "Landscape" this keeps the horizontal screen.
two . when we encounter different sizes of resolutions, 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 to put pictures of high-resolution phones, such as: 854*480, 800*480
Second file folder in the resolution of the image of the phone, such as: 480*320
The third folder puts pictures of low-resolution phones, such as: 320*240
About layout and horizontal screen switch to vertical screen, you just need to create a different layout folder in the Res directory, such as layout-480x320, layout-800x480, the system will choose the appropriate layout to use according to the size of the screen.
When a horizontal screen switches to a vertical screen, you encounter an issue, how do I create the layout folder?
is all of the layout folders in my project:
Layouts is a placement folder for high resolution vertical screens
Layout-land is a layout folder for high resolution horizontal screen;
layout-land-320x240 is a layout folder for a low resolution horizontal screen;
layout-land-480x320 is a layout folder that fits in the horizontal resolution of the screen The
layout-port-320x240 is a layout folder for a low resolution vertical screen;
layout-port-480x320 is a layout folder for a vertical screen in the appropriate resolution;
The layout file is finished.
I personally feel that the development of high-resolution simulator is better, and then to do the various resolutions of the adaptation. Sometimes when we layout, low-resolution layouts may need to be modified.
Finally, there is one more question. What if I write a dead layout in a Java program?
This is annoying, you need to determine the size of the screen, the code to get the screen size is as follows:
Java code
1
2 WindowManager WindowManager = Getwindowmanager ();
3 Display display = Windowmanager.getdefaultdisplay ();
4 int screenwidth = Display.getwidth ();
5 int screenheight = Display.getheight ();
The following code snippet is used by myself in the program to write dead layouts, for informational purposes only:
Java code:
Button cancelbtn = New button (this);
if (screenwidth<320 | | screenheight<320)
Cancelbtn.setlayoutparams (New Layoutparams (Android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
else if (screenwidth <480 &&screenheight = = 480)
Cancelbtn.setlayoutparams (New Layoutparams (Android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
else if (screenwidth >480 && screenheight = = 480)
Cancelbtn.setlayoutparams (New Layoutparams (Android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
Else
Cancelbtn.setlayoutparams (New Layoutparams (Android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
Similar to the principle of internationalization, here I simply say,
Create a new Values-en,values-en-rus,values-zh folder,
How to verify that internationalization is successful? Change the phone system's default language to English, or American English, the specific code see the next blog content!
Android Adaptive screen resolution and internationalization