What does Android studio do with screen adaptation?

Source: Internet
Author: User

I. Recommendations on layout adaptation
1. Do not use absolute layout
2, try to use match_parent instead of fill_parent.
3, can use the heavy place as far as possible to use the weight (android:layout_weight)
4, if it is a solid color background, try to use the shape of Android to customize.
5. If you need to fit at a specific resolution, you can create a new Layout-hxw.xml folder on the Res directory. For example, to fit the 1080*1800 screen (Meizu MX3 with this resolution), create a new Layout-1800x1080.xml folder and define the layout below. The Android system will first look for layouts with the same resolution and, if they don't exist, use the default layout under layouts.

Ii. Terminology and Concepts
Four Screen size categories:: Small, normal, large, and XLarge
Four density classifications: ldpi (Low), MDPI (Medium), hdpi (High), and xhdpi (extra high)
It is important to note that XHDPI is the only category that has been added since Android 2.2 (API Level 8).
XLarge is the category that was added from Android 2.3 (API Level 9).
DPI is the abbreviation for "dot per inch" and the number of pixels per inch.
General screen: LDPI is 120,mdpi is 160,hdpi is 240,xhdpi is 320.

third, how to achieve adaptive screen size?
1) interface layout aspect
It is necessary to prepare 5 sets of layouts according to the size of the physical size, layout (put some common layout XML files, such as the top and bottom layouts in the interface, will not change with the screen size, like the title bar of the WinDOS window), Layout-small ( Screen size less than 3 inches in layout), layout-normal (screen size less than 4.5 inches or so), Layout-large (4 inches-7 inches), Layout-xlarge (7-10 inches)
2) Picture Resources
5 sets of picture resources need to be prepared according to the DPI value, drawable,drawalbe-ldpi,drawable-mdpi,drawable-hdpi,drawable-xhdpi
Android has an automatic matching mechanism to select the corresponding layout and picture resources

Four, two ways to obtain screen resolution information:
displaymetrics metrics = new Displaymetrics ();
Display display = Activity.getwindowmanager (). Getdefaultdisplay ();
display.getmetrics (metrics);
//The pixel value obtained here is the device independent pixel DP
//displaymetrics metrics=activity.getresources (). Getdisplaymetrics (); The parameter information obtained is incorrect, do not use this method.
You cannot use Android.content.res.Resources.getSystem (). Getdisplaymetrics (). This gets the width and height is empty.

What does Android studio do with screen adaptation?

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.