Android screen adaptation Autolayout

There are many Android screen adaptations, such as image adaptation, code adaptation, weight adaptation, layout adaptation, size adaptation, etc. AutoLayout is a new adaptation method and can be called the terminator of adaptation. In development, I prefer the adaptation method of AutoLayout. The convenience and effect of AutoLayout adaptation are far better than the previous adaptation method. I briefly summarize the usage of Autolayout:
(1) Register the size
of the design drawing Introduce autolayout into the configuration dependencies {compile project(':autolayout')}, and indicate the appropriate UI size in AndroidManifest.
(2) Enable settings
in Activity Inherit AutoLayoutActivity in Activity
(3) Enable PreView
  1. In the PreView panel, select a device with the same resolution as the UI size.
  2. When the size of the design drawing given by the UI is not the mainstream design drawing, and the size is not found, we can create a new device with the display.
  3. Don't check the display at all resolutions in PreView, you can't see the adaptation effect, because some calculations are dynamic.
(4) TextView settings
 For the upper and lower margins of TextView and other controls, write as small as possible. For example, when writing Item, you can reduce the marginTop value.
(5) Specify the value of the set reference width or height
The width and height of 1px in the layout file are not equal. If you need to keep the width and height consistent, use app:layout_auto_basewidth="height" and app:layout_auto_baseheight="width" in the layout; if you need to specify multiple values ​​to refer to the width, Use app:layout_auto_basewidth="height|padding", separated by |, similar to the usage of gravity.
(6) Use the status bar area as the content area
If an Activity needs to use the status bar area as the actual content area, the available height will become larger. Implement the UseStatusBar interface in the Activity,
enable windowTranslucentStatus or set FLAG_TRANSLUCENT_STATUS.
(7) Currently supports attributes
layout_width, layout_height, layout_margin(left,top,right,bottom), pading(left,top,right,bottom), textSize, which will not affect all other attributes of the system, and will not affect dp,sp usage of.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326995260&siteId=291194637