Adaptive orientation size for Android screen

Source: Internet
Author: User

Recently feel like to be the screen fit to play dead ...
Android phone for shrimp can not be like Apple, just a few resolutions? Why,!!!!!!!? Amen......
There are two ways to solve this problem now ...
The first type:
Html5+css3+webview interaction ... Currently in the study, empty put demo
The second type:
Handled by the Android UI's own layout:
1. Screen interface layout
Create different layout (drawable) folders in the Res directory, such as layout-640x360, layout-800x480, and all layout files will be written to R.java after compilation. And the system will be based on the size of the screen to choose the appropriate layout for use
2. Multi-resolution Support
Support multi-resolution with MDPI, LDPI, hdpi 3 files.
HDPI inside storage high-resolution pictures, such as WVGA (480x800), FWVGA (480x854); (PS: I very tangled 480*854 resolution, Tangled!!!!) )
MDPI contains medium-resolution images, such as HVGA (320x480);
LDPI contains low-resolution images, such as QVGA (240x320).
The system will be based on the resolution of the machine to the respective folders to find the corresponding picture, in the program development, in order to be compatible with different platforms different screens, it is recommended that different versions of the picture according to the needs of the corresponding folder.
3. Get the screen size

Java code
  1. Displaymetrics metric = new Displaymetrics ();
  2. Getwindowmanager (). Getdefaultdisplay (). Getmetrics (Metric);
  3. int width = metric.widthpixels; //Screen width (pixels)
  4. int height = metric.heightpixels; //Screen height (pixels)
  5. float density = metric.density; //Screen density (0.75/1.0/1.5)
  6. int densitydpi = metric.densitydpi; //Screen density dpi (120/160/240)


In a low-density small screen mobile phone, the above code is not able to get the correct size. Therefore, it is necessary to add the Supports-screens node in the project's Androidmanifest.xml file, the specific content is as follows:

XML code
    1. <supports-screens  
    2.        android:smallscreens=
    3.        android:normalscreens=" true "&NBSP;&NBSP;
    4.        android:largescreens= "true" &NBSP;&NBSP;
    5.        android:resizeable=
    6.        android:anydensity= "true"  />  


4. There are automatic horizontal screens and the like, not ready to support ... Yes ~ Amen ... android:screenorientation= "portrait" All Vertical ...

Adaptive orientation size for Android screen

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.