Android adaptation-minimum width qualifier

1. Why adapt

Android's system fragmentation, model and screen size fragmentation, and screen resolution fragmentation are serious. We urgently need a better adaptation method to allow the interface view to be displayed normally on each device.

2. Adapt relevant knowledge concepts

Physical pixel (px): Represents the physical pixel of the mobile phone.
Density-independent pixel (dp): A density-independent pixel is equal to a physical pixel on the 160dpi screen. This is the baseline density of the system.
Screen density (dpi): per inch of the screen For pixels, Android groups all screen densities into 6 common densities: low (ldpi), medium (mdpi), high (hdpi), super high (xhdpi), xxhdpi and xxxhdpi.

Get the physical pixel size of the device 1280px X 800px

adb shell wm size

Get device DPI=213 (this strange command is called density)

adb shell wm density

Android screen adaptation-basic knowledge of
Android screen adaptation

3. Minimum width qualifier

Calculate the minimum width

smallestWidth = min(H,W)/(DPI/160)

According to the pixel (1280px X 800px) and DPI (213) for the example in Title 2 (this is a tablet Android device that I really encountered in development).

  • min(H,W): The minimum width does not distinguish the direction, and the minimum width and height are the minimum width.

  • The design drawing can be understood as your own unit according to 1280 X 800 units, such as: dpp

  • For example: 1280dp (px here is directly considered 1dp = 1px) X 800dp (px) the real smallestWidth = 800/(213/160) = 600dp

  • Generate folder: values-sw600dp

  • The generation ratio is: 600dp/minimum width of the design drawing 1dpp = 600dp/800dpp = 0.75dp

  • So 1dpp is converted to 0.75dp

<dimen name="dpp1">0.7500dp</dimen>
...
<dimen name="dpp10">7.5000dp</dimen>

Use ScreenMatch to generate folders of different widths

############################################################################
# Start with '#' is annotate.                                              #
# In front of '=' is key, cannot be modified.                              #
# More information to visit:                                               #
#   http://blog.csdn.net/fesdgasdgasdg/article/details/52325590            #
#   http://download.csdn.net/detail/fesdgasdgasdg/9913744                  #
#   https://github.com/mengzhinan/PhoneScreenMatch                         #
############################################################################
#
# You need to refresh or reopen the project every time you modify the configuration,
# or you can't get the latest configuration parameters.
#
#############################################################################
#
# Base dp value for screen match. Cut the screen into [base_dp] parts.
# Data type is double. System default value is 360.
# I advise you not to modify the value, be careful !!!!!!!!! _^_  *_*
base_dp=800
# Also need to match the phone screen of [match_dp].
# If you have another dp values.
# System default values is 384,392,400,410,411,480,533,592,600,640,662,720,768,800,811,820,960,961,1024,1280,1365
match_dp=600,1080
# If you not wanna to match dp values above. Write some above values here, append value with "," .
# For example: 811,961,1365
ignore_dp=384,392,400,410,411,432,480,533,592,640,662,720,768,800,811,820,960,961,1024,1280,1365
# They're not android module name. If has more��split with , Symbol.
# If you set, it will not show in SelectDialog.
# If you have, write here and append value with "," .
# For example: testLibrary,commonModule
# System default values is .gradle, gradle, .idea, build, .git
ignore_module_name=
# Use which module under the values/dimen.xml file to do the base file,
# and generated dimen.xml file store in this module?
# Default value is 'app'.
match_module=app
# Don't show select dialog again when use this plugin.
# System screen match will use the last selected module name or default module name.
# You can give value true or false. Default value is false.
not_show_dialog=false
# Do you want to generate the default example dimens.xml file?
# In path of .../projectName/screenMatch_example_dimens.xml, It does not affect your project code.
# You can give value true or false. Default value is false.
not_create_default_dimens=false
# Does the font scale the same size as the DP? May not be accuracy.
# You can give value true or false. Default value is true. Also need scaled.
is_match_font_sp=false
# Do you want to create values-wXXXdp folder or values-swXXXdp folder ?
# I suggest you create values-swXXXdp folder,
# because I had a problem when I was working on the horizontal screen adapter.
# values-swXXXdp folder can solve my problem.
# If you want create values-swXXXdp folder, set "create_values_sw_folder=true",
# otherwise set "create_values_sw_folder=true".
# Default values is true.
create_values_sw_folder=true

Other adaptation methods

  1. dp direct adaptation
  2. Width and height qualifier
  3. Modify density (today's headline plan)

Android Screen Adaptation-App Article
Sao Nian, your screen adaptation method should be upgraded!-smallestWidth qualifier adaptation scheme

Guess you like

Origin blog.csdn.net/u011148116/article/details/106329126