Android screen adaptive orientation and android adaptive Orientation
Recently, I feel like I am getting stuck on the screen ......
The Android phone is Xiami. How many resolutions can it have? Why !!!!!!! Amen ......
There are two solutions ......
First:
HTML5 + CSS3 + WebView interaction ...... I am still studying it. I am leaving the demo empty.
Second:
Use the android UI's own layout to handle the following:
1. Screen Layout
Create different layout (drawable is also supported) folders under the res directory, such as layout-640x360, layout-800x480, all layout files will be written to R after compilation. java, and the system will select the appropriate layout based on the screen size.
2. Multi-Resolution Support
Supports mdpi, ldpi, and hdpi files with multiple resolutions.
Hdpi stores high-resolution images, such as WVGA (480x800) and FWVGA (480x854, tangle !!!!)
The mdpi contains medium-resolution images, such as HVGA (320x480 );
Ldpi stores low-resolution images, such as QVGA (240x320 ).
The system will go to these folders to find the corresponding images based on the machine resolution. In program development, in order to be compatible with different screens of different platforms, we recommend that you store images of different versions in the corresponding folders as needed.
3. Get the screen size
Java code
- DisplayMetrics metric = new DisplayMetrics ();
- GetWindowManager (). getDefaultDisplay (). getMetrics (metric );
- Int width = metric. widthPixels; // screen width (pixels)
- Int height = metric. heightPixels; // screen height (pixels)
- Float density = metric. density; // screen density (0.75/1.0/1.5)
- Int densityDpi = metric. densityDpi; // screen density DPI (120/160/240)
In other words, on a low-density cell phone, the correct size cannot be obtained only by relying on the above Code. Therefore, add the supports-screens node to the AndroidManifest. xml file of the project. The specific content is as follows:
Xml Code
- <Supports-screens
- Android: smallScreens = "true"
- Android: normalScreens = "true"
- Android: largeScreens = "true"
- Android: resizeable = "true"
- Android: anyDensity = "true"/>
4. There are also automatic horizontal screens and so on, not supported ...... En ~ Amen ...... Android: screenOrientation = "portrait" All vertical...
How does the Android program adapt to the orientation and size of the screen?
Different Android targets have different sizes. the application interface needs to adjust the size of interface elements for different sizes. In addition, the screen can be switched between the landscape screen and the portrait screen, and the interface also needs to be adjusted. By default, when the screen is switched, The onCreate () method of the activity will be called again, so you can use the following code to read the screen direction: public void onCreate () {if (this. getResources (). getConfiguration (). orientation = Configuration. ORIENTATION_LANDSCAPE) {Log. I ("info", "landscape");} else if (this. getResources (). getConfiguration (). orientation = Configuration. ORIENTATION_PORTRAIT) {Log. I ("info", "portrait") ;}} if you are in androidmanifest. add android: configChanges = "orientation | keyboardHidden | navigation in xml. When the screen is flipped, the Activity will not repeatedly call onCreate (), onPause (), and onResume (). instead, call onConfigurationChanged (Configuration newConfig) int screenWidth, screenHeight; WindowManager windowManager = getWindowManager (); Display display = windowManager. getdefadisplay display (); screenWidth = display. getWidth (); screenHeight = display. getHeight (); someone also mentioned another method: DisplayMetrics dm = new DisplayMetrics (); getWindowManager (). getdefadisplay display (). getMetrics (dm );
In android, how does one make the program adaptive to the screen size?
This is a problem involving screen resolution. First, you have to get the screen size of the device and then call resources that are closer to the device. This resource is the folders in the res directory of your project, than the film has three folders, placed in different sizes, the following layout XML, as shown in: layout-240x480, the xml corresponds to the corresponding size of the image; do not know if you have any help