CN105827833A - Percentage-based Android mobile phone screen adaption method - Google Patents

Percentage-based Android mobile phone screen adaption method Download PDF

Info

Publication number
CN105827833A
CN105827833A CN201610164574.1A CN201610164574A CN105827833A CN 105827833 A CN105827833 A CN 105827833A CN 201610164574 A CN201610164574 A CN 201610164574A CN 105827833 A CN105827833 A CN 105827833A
Authority
CN
China
Prior art keywords
resolution
adaptation
screen
mobile phone
file
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201610164574.1A
Other languages
Chinese (zh)
Inventor
钱程
蒋国平
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nanjing Post and Telecommunication University
Original Assignee
Nanjing Post and Telecommunication University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nanjing Post and Telecommunication University filed Critical Nanjing Post and Telecommunication University
Priority to CN201610164574.1A priority Critical patent/CN105827833A/en
Publication of CN105827833A publication Critical patent/CN105827833A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04MTELEPHONIC COMMUNICATION
    • H04M1/00Substation equipment, e.g. for use by subscribers
    • H04M1/72Mobile telephones; Cordless telephones, i.e. devices for establishing wireless links to base stations without route selection
    • H04M1/724User interfaces specially adapted for cordless or mobile telephones
    • H04M1/72403User interfaces specially adapted for cordless or mobile telephones with means for local support of applications that increase the functionality
    • H04M1/72427User interfaces specially adapted for cordless or mobile telephones with means for local support of applications that increase the functionality for supporting games or graphical animations

Landscapes

  • Engineering & Computer Science (AREA)
  • Human Computer Interaction (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Stored Programmes (AREA)
  • Telephone Function (AREA)

Abstract

本发明公开了一种基于百分比的Android手机屏幕适配方法,该方法针对现有的Android手机屏幕适配方案的不足,提出了一种根据屏幕尺寸和像素无关密度之间的映射关系的基于百分比的屏幕适配方案。主要包括确定需要适配的手机屏幕分辨率、将需要适配的手机屏幕分辨率在横向和纵向上以UI基准进行等分,计算出在这个基准下一个单元的高度和宽度所分别对应的像素值、然后通过编程,自动生成适配文件的工具类,生成需要适配的分辨率所对应的XML文件、引用适配文件中对应数值的方式设置控件的参数,系统会根据当前设备的分辨率找到准确的像素值设置给控件,从而可以实现准确的适配。本发明利用了Android系统自适应特性,与传统适配方案相比,可以精确地适配不同手机分辨率。

The invention discloses a percentage-based Android mobile phone screen adaptation method. The method aims at the deficiency of the existing Android mobile phone screen adaptation scheme, and proposes a percentage-based method according to the mapping relationship between the screen size and the pixel-independent density. screen adaptation scheme. It mainly includes determining the screen resolution of the mobile phone that needs to be adapted, dividing the screen resolution of the mobile phone that needs to be adapted to the UI benchmark in the horizontal and vertical directions, and calculating the pixels corresponding to the height and width of a unit under this benchmark Value, and then through programming, automatically generate the tool class of the adaptation file, generate the XML file corresponding to the resolution that needs to be adapted, and set the parameters of the control by referring to the corresponding value in the adaptation file. The system will use the resolution of the current device Find the exact pixel value to set to the control, so that an accurate fit can be achieved. The invention utilizes the self-adaptive characteristic of the Android system, and can accurately adapt to different mobile phone resolutions compared with the traditional adaptation scheme.

Description

一种基于百分比的Android手机屏幕适配方法A percentage-based screen adaptation method for Android mobile phones

技术领域technical field

本发明涉及一种图像数据处理领域中的图像转换技术,具体涉及一种针对Android系统移动终端的屏幕适配方法。The invention relates to an image conversion technology in the field of image data processing, in particular to a screen adaptation method for a mobile terminal of an Android system.

背景技术Background technique

随着互联网的迅速发展,移动客户端应用的开发被推到了风口浪尖。根据报告显示在中国市场上Android系统的市场份额2014年己经增加至86%,并且还在不断提升。在国内市场上,像小米的MIUI、华为的EMUI、魅族的Flyme系统等,都是在Android系统基础上深度定制的操作系统,以此来满足国人的使用习惯。但是正是由于这种开放性,使得Android系统的定制参差不齐。不同厂商可以根据自身需要定制系统,因此出现了“碎片化”问题。如图1所示。该图中每一个矩形代表一种Android设备屏幕尺寸。With the rapid development of the Internet, the development of mobile client applications has been pushed to the forefront. According to the report, the market share of the Android system in the Chinese market has increased to 86% in 2014, and it is still increasing. In the domestic market, Xiaomi's MIUI, Huawei's EMUI, and Meizu's Flyme system are all deeply customized operating systems based on the Android system to meet the usage habits of Chinese people. But it is precisely because of this openness that the customization of the Android system is uneven. Different manufacturers can customize the system according to their own needs, so there is a "fragmentation" problem. As shown in Figure 1. Each rectangle in the figure represents an Android device screen size.

传统的适配解决方法是,在编写布局文件时尽量使用wrap_content、match_parent、weight属性来设定一个控件的宽和高。使用wrap_content,系统就会将视图的宽度或高度设置成所需的最小尺寸以适应视图中的内容,而match_parent(在低于API级别8的级别中称为fill_parent)则会展开组件以填充其父视图的尺寸。而weight则是线性布局(LinerLayout)中的特有属性,我们可以根据纵向或者横向的控件个数和weight的本比例来对界面进行分配。但是如果想要界面变得更加美观、更加符合用户的使用习惯,仅仅凭借这种方法是远远不够的。所以我们想到了像素无关的密度单位dp和sp来控制控件的长宽。虽然dp可以使相同的控件在不同的屏幕下显示的效果近似,但是并不是所有的屏幕宽度都是相同的dp长度。当设备的物理尺寸存在差异的时候,dp就显得无能为力了。比如为4.3寸屏幕准备的UI,运行在5.0寸的屏幕上,很可能在右侧和下侧存在大量的空白;而5.0寸的UI运行到4.3寸的设备上,就无法全部显示。所以上述传统适配解决方法并不能解决所有适配问题,虽然dp能够让同一数值在不同分辨率展示出大致相同的尺寸大小,比如,公开号为CN103905643A的发明针对不同分辨率的手机屏幕需要使用不同分辨率的背景图片的问题,提出了一种单一背景图片手机适配方法,但是当设备的尺寸差异较大时,这种方法就无能为力了。The traditional adaptation solution is to use wrap_content, match_parent, and weight attributes as much as possible to set the width and height of a control when writing layout files. With wrap_content, the system will set the width or height of the view to the minimum size required to fit the content in the view, while match_parent (called fill_parent in levels lower than API level 8) will expand the component to fill its parent The dimensions of the view. The weight is a unique attribute in the linear layout (LinerLayout), we can allocate the interface according to the number of vertical or horizontal controls and the ratio of the weight. But if you want the interface to become more beautiful and more in line with the user's usage habits, this method alone is not enough. So we thought of pixel-independent density units dp and sp to control the length and width of the control. Although dp can approximate the effect of the same control displayed on different screens, not all screen widths have the same dp length. When there is a difference in the physical size of the device, dp is powerless. For example, if a UI prepared for a 4.3-inch screen runs on a 5.0-inch screen, there may be a large amount of blank space on the right and bottom sides; while the 5.0-inch UI runs on a 4.3-inch device, it cannot be fully displayed. Therefore, the above-mentioned traditional adaptation solution cannot solve all adaptation problems, although dp can make the same value display roughly the same size at different resolutions, for example, the invention with the publication number CN103905643A needs to use To solve the problem of background images with different resolutions, a single background image mobile phone adaptation method is proposed, but when the sizes of devices vary greatly, this method is powerless.

Android手机的屏幕适配一直以来都是开发者必须要面对的一个头疼的问题。从手机到平板,现在市面上各种移动设备屏幕尺寸和分辨率各式各样,Android开发者在完善应用的功能的同时还需要对参差不齐的设备和定制化系统完成适配,以提高用户体验,这需要分散相当大的时间和精力。所以提出一种快速准确可复用的屏幕适配方案势在必行。The screen adaptation of Android phones has always been a headache that developers have to face. From mobile phones to tablets, there are various screen sizes and resolutions of mobile devices on the market. While improving the functions of applications, Android developers also need to adapt to the uneven devices and customized systems to improve User experience, which requires a considerable scatter of time and effort. Therefore, it is imperative to propose a fast, accurate and reusable screen adaptation solution.

发明内容Contents of the invention

本发明针对上述现有的Android手机屏幕适配方案的不足,提出了一种根据屏幕尺寸和像素无关密度(DensityIndependentPixels)之间的映射关系的基于百分比的屏幕适配方案。Aiming at the shortcomings of the above-mentioned existing screen adaptation schemes for Android mobile phones, the present invention proposes a percentage-based screen adaptation scheme according to the mapping relationship between screen size and pixel-independent density (DensityIndependentPixels).

本发明在屏幕尺寸和像素无关密度之间映射关系的基础上,提出了一种基于百分比的手机屏幕适配方法,可以便捷准确的完成屏幕适配工作,使开发者可以设计出更加丰富多彩并且有较好交互体验的用户界面。包括以下步骤:On the basis of the mapping relationship between screen size and pixel-independent density, the present invention proposes a percentage-based mobile phone screen adaptation method, which can conveniently and accurately complete the screen adaptation work, enabling developers to design more colorful and User interface with better interactive experience. Include the following steps:

(1)根据项目需求确定需要适配的手机屏幕分辨率,包括市面上主流的分辨率以及特殊的分辨率(比如平板等)。(1) Determine the screen resolution of the mobile phone that needs to be adapted according to the project requirements, including mainstream resolutions on the market and special resolutions (such as tablets, etc.).

(2)以UI给出的设计图的分辨率为基准,将需要适配的手机屏幕分辨率在横向和纵向上以这个基准进行等分,并计算出在这个基准下一个单元的高度和宽度所分别对应的像素值。(2) Taking the resolution of the design drawing given by the UI as the benchmark, the screen resolution of the mobile phone to be adapted is equally divided horizontally and vertically by this benchmark, and the height and width of a unit under this benchmark are calculated corresponding pixel values.

(3)然后通过文件输入输出流的编程,实现自动生成适配文件的工具类,生成需要适配的分辨率所对应的values文件夹,以"values-需要适配的分辨率"的格式对该文件夹进行命名,该文件夹下包含两个文件,分别是记录屏幕宽度像素值和屏幕高度像素值的XML文件,这些像素值来自步骤2中的计算结果。(3) Then, through the programming of the file input and output stream, the tool class for automatically generating the adaptation file is realized, and the values folder corresponding to the resolution that needs to be adapted is generated, and the format is "values-the resolution that needs to be adapted" The folder is named, and this folder contains two files, which are XML files that record the screen width pixel value and the screen height pixel value, and these pixel values come from the calculation results in step 2.

(4)在编写布局文件时,直接使用设计图上的px数值,即通过引用适配文件中对应数值的方式设置控件的属性以及距离,系统会根据当前设备的分辨率到步骤3中生成的values文件夹中找到准确的像素值设置给控件,从而可以实现准确的适配。(4) When writing the layout file, directly use the px value on the design drawing, that is, set the properties and distance of the control by referencing the corresponding value in the adaptation file, and the system will use the resolution of the current device to generate in step 3 Find the accurate pixel value in the values folder and set it to the control, so that accurate adaptation can be achieved.

如果需要适配一些特殊的分辨率,则通过命令行的方式将需要适配的特殊分辨率以参数的形式输入,生成需要适配分辨率的适配文件,然后根据Android系统的自适应特性,将这些适配文件夹加入Android项目的res目录下,最后执行步骤4,完成准确的适配。If some special resolutions need to be adapted, input the special resolutions that need to be adapted as parameters through the command line, generate an adaptation file that needs to be adapted to the resolution, and then according to the adaptive characteristics of the Android system, Add these adaptation folders to the res directory of the Android project, and finally perform step 4 to complete accurate adaptation.

有益效果:本发明根据目前Android项目开发过程中屏幕适配方案的不足,提出了一种根据屏幕尺寸和像素无关密度(DensityIndependentPixels)之间的映射关系的基于百分比的屏幕适配方案。该方案具有以下优点:Beneficial effects: the present invention proposes a percentage-based screen adaptation scheme based on the mapping relationship between screen size and pixel-independent pixels (DensityIndependentPixels) according to the deficiency of the screen adaptation scheme in the current Android project development process. This scheme has the following advantages:

(1)根据Android系统自适应特性,计算得到不同分辨率下对应的像素值,所以与传统适配方案相比可以精确地适配不同手机分辨率。(1) According to the adaptive characteristics of the Android system, the corresponding pixel values at different resolutions are calculated, so compared with the traditional adaptation scheme, it can accurately adapt to different mobile phone resolutions.

(2)该方案是以UI给出的设计图分辨率为基准,以开发者可以直接使用设计图中标注的px数值设置宽高属性,非常便捷,减轻了开发者在px和dp之间转换的压力。(2) This solution is based on the resolution of the design drawing given by the UI, and the developer can directly use the px value marked in the design drawing to set the width and height attributes, which is very convenient and reduces the need for developers to switch between px and dp pressure.

(3)并且分辨率是以基准进行等分,很容易实现类似于WEB网页布局中的百分比布局,而这正是Android布局中所不具有的属性。(3) And the resolution is equally divided by the benchmark, it is easy to implement a percentage layout similar to the WEB page layout, and this is an attribute that the Android layout does not have.

(4)该方案生成的各个分辨率是适配文件是通用的,不同项目可以使用相同的适配文件,所以具有很好的复用性。(4) The adaptation files for each resolution generated by this solution are common, and different projects can use the same adaptation file, so it has good reusability.

(5)若需要添加新的适配分辨率只需要通过命令行的方式,就可以快速生成对应的分辨率的适配文件,具有很好的扩展性。(5) If you need to add a new adaptation resolution, you only need to use the command line to quickly generate the adaptation file of the corresponding resolution, which has good scalability.

附图说明Description of drawings

图1是反映目前Android设备屏幕“碎片化”问题的示意图。Figure 1 is a schematic diagram reflecting the problem of "fragmentation" of the screen of an Android device at present.

图2是本发明适配方案的流程图。Fig. 2 is a flow chart of the adaptation scheme of the present invention.

图3是本发明一个实施例的适配流程图。Fig. 3 is an adaptation flowchart of an embodiment of the present invention.

具体实施方式detailed description

现结合附图对本发明的具体实施作进一步的说明。The specific implementation of the present invention will be further described in conjunction with the accompanying drawings.

本发明在屏幕尺寸和像素无关密度之间映射关系的基础上,提出了一种基于百分比的手机屏幕适配方法,可以便捷准确的完成屏幕适配工作,使开发者可以设计出更加丰富多彩并且有较好交互体验的用户界面。如图2所示,包括以下步骤:On the basis of the mapping relationship between screen size and pixel-independent density, the present invention proposes a percentage-based mobile phone screen adaptation method, which can conveniently and accurately complete the screen adaptation work, enabling developers to design more colorful and User interface with better interactive experience. As shown in Figure 2, it includes the following steps:

(1)根据项目需求确定需要适配的手机屏幕分辨率,包括市面上主流的分辨率以及特殊的分辨率(比如平板等)。(1) Determine the screen resolution of the mobile phone that needs to be adapted according to the project requirements, including mainstream resolutions on the market and special resolutions (such as tablets, etc.).

(2)以UI给出的设计图的分辨率为基准,将需要适配的手机屏幕分辨率在横向和纵向上以这个基准进行等分,并计算出在这个基准下一个单元的高度和宽度所分别对应的像素值。(2) Taking the resolution of the design drawing given by the UI as the benchmark, the screen resolution of the mobile phone to be adapted is equally divided horizontally and vertically by this benchmark, and the height and width of a unit under this benchmark are calculated corresponding pixel values.

(3)然后通过文件输入输出流的编程,实现自动生成适配文件的工具类,生成需要适配的分辨率所对应的values文件夹,以"values-需要适配的分辨率"的格式对该文件夹进行命名,该文件夹下包含两个文件,分别是记录屏幕宽度像素值和屏幕高度像素值的XML文件,这些像素值来自步骤2中的计算结果。(3) Then, through the programming of the file input and output stream, the tool class for automatically generating the adaptation file is realized, and the values folder corresponding to the resolution that needs to be adapted is generated, and the format is "values-the resolution that needs to be adapted" The folder is named, and this folder contains two files, which are XML files that record the screen width pixel value and the screen height pixel value, and these pixel values come from the calculation results in step 2.

(4)在编写布局文件时,直接使用设计图上的px数值,即通过引用适配文件中对应数值的方式设置控件的属性以及距离,系统会根据当前设备的分辨率到步骤3中生成的values文件夹中找到准确的像素值设置给控件,从而可以实现准确的适配。(4) When writing the layout file, directly use the px value on the design drawing, that is, set the properties and distance of the control by referencing the corresponding value in the adaptation file, and the system will use the resolution of the current device to generate in step 3 Find the accurate pixel value in the values folder and set it to the control, so that accurate adaptation can be achieved.

如果需要适配一些特殊的分辨率,则通过命令行的方式将需要适配的特殊分辨率以参数的形式输入,生成需要适配分辨率的适配文件,然后根据Android系统的自适应特性,将这些适配文件夹加入Android项目的res目录下,最后执行步骤4,完成准确的适配。If some special resolutions need to be adapted, input the special resolutions that need to be adapted as parameters through the command line, generate an adaptation file that needs to be adapted to the resolution, and then according to the adaptive characteristics of the Android system, Add these adaptation folders to the res directory of the Android project, and finally perform step 4 to complete accurate adaptation.

本发明还提供了一个实施例,其适配案实施的步骤流程图如图3所示。在采用该方案进行Android设备的屏幕适配时,首先需要根据项目需求确定需要适配的分辨率,包括市场上主流的手机屏幕分辨率以及需要适配的一些特殊的分辨率。然后以UI设计的效果图的分辨率选为基准分辨率。一般UI在设计效果图时其分辨率固定,如设计图是按照480*320的分辨率设计的则选取480*320的分辨率为基准;编写JAVA工具类实现适配文件的自动生成。自动生成的文件包含主流分辨率,若需要适配其它分辨率可以通过命令行的形式实现;最后再将生成的适配文件加入到项目里,布局时引用即可完成适配工作。The present invention also provides an embodiment, and the flow chart of the implementation steps of the adaptation solution is shown in FIG. 3 . When using this solution to adapt the screen of Android devices, it is first necessary to determine the resolution that needs to be adapted according to the project requirements, including the mainstream mobile phone screen resolution in the market and some special resolutions that need to be adapted. Then select the resolution of the rendering of the UI design as the benchmark resolution. Generally, the resolution of the UI is fixed when designing the effect diagram. If the design diagram is designed according to the resolution of 480*320, the resolution of 480*320 is selected as the benchmark; the JAVA tool class is written to realize the automatic generation of the adaptation file. The automatically generated file contains mainstream resolutions. If you need to adapt to other resolutions, you can implement it through the command line; finally, add the generated adaptation file to the project, and reference it during layout to complete the adaptation work.

现对以上步骤做详细说明:Now describe the above steps in detail:

步骤1:在适配时,需要确定需要适配的分辨率。除了适配市面上比较主流的分辨率以外,还需根据项目需要适配一些比较特殊的分辨率,例如一些应用需要同时面向手机端用户和平板设备用户,则一些平板设备的分辨率也是需要考虑在内的。具体的市场上存在的设备分辨率可以通过如下的网址进行查询:http://screensiz.es/phoneStep 1: When adapting, it is necessary to determine the resolution to be adapted. In addition to adapting to the mainstream resolutions on the market, some special resolutions need to be adapted according to the needs of the project. For example, some applications need to target both mobile phone users and tablet device users, so the resolution of some tablet devices also needs to be considered. included. Specific device resolutions in the market can be queried through the following URL: http://screensiz.es/phone .

步骤2:需要确认一个基准分辨率,并以此来计算在不同分辨率下宽度每份x1以及高度每份y1所占的像素px值。一般在一个项目开发过程中UI会提供每个界面的设计效果图,Android开发者需要根据这个效果图来编写界面的布局。这些界面效果图一般都是基于同一分辨率。例如UI给出的效果图是基于320*480分辨率的,那么可以此分辨率为基准,将任何分辨率的宽度分为320份,取值为x1-x320;将任何分辨率的高度分为480份,取值为y1-y480。然后计算出在任意分辨率下x1和y1所占的像素数。例如适配320*480分辨率的屏幕,由于该分辨率与基准相同,则对应的x1=1px,y1=1px。若需要适配1080*1920的屏幕,则根据x1=1080/基准=1080/320=3.37px,y1=1920/基准=1920/480=4px。以此类推分别计算出x1-x320以及y1-y480。另外在设计图中控件的宽高和距离都是通过px单位标注的,所以可以直接将px转化为x[1-320],y[1-480],这样在编写布局时可以直接使用设计图上的尺寸就可以完成全分辨率的适配了。不用再像以前一样要根据设计图的px计算出一个适中的dp值再设置宽高,并且这种方法在不同屏幕尺寸和分辨率下显示效果也是有差异的,影响用户体验。Step 2: It is necessary to confirm a benchmark resolution, and use it to calculate the pixel px value occupied by each x1 of width and y1 of height under different resolutions. Generally, during the development of a project, the UI will provide the design renderings of each interface, and Android developers need to write the layout of the interface according to the renderings. These interface renderings are generally based on the same resolution. For example, the effect picture given by the UI is based on the resolution of 320*480, then this resolution can be used as a benchmark to divide the width of any resolution into 320 parts, and the value is x1-x320; the height of any resolution is divided into 480 copies, the value is y1-y480. Then calculate the number of pixels x1 and y1 occupy at any resolution. For example, to adapt to a screen with a resolution of 320*480, since the resolution is the same as the reference, the corresponding x1=1px, y1=1px. If it is necessary to adapt to a 1080*1920 screen, according to x1=1080/baseline=1080/320=3.37px, y1=1920/baseline=1920/480=4px. By analogy, x1-x320 and y1-y480 are calculated respectively. In addition, the width, height and distance of the controls in the design diagram are marked by px units, so px can be directly converted into x[1-320], y[1-480], so that the design diagram can be used directly when writing the layout The above size can complete the full resolution adaptation. It is no longer necessary to calculate a moderate dp value based on the px of the design drawing and then set the width and height as before, and this method also has different display effects under different screen sizes and resolutions, which affects the user experience.

步骤3:通过上述介绍可知,我们需要为适配的每一种分辨率生成一个适配文件夹。文件夹的命名规则是valuse+适配分辨率。例如用于适配1920*1080分辨率的文件夹名称为values-1920x1080。该文件夹下包含两个XML文件,分别为lay_x.xml里面包含x1-x320所对应的px值以及lay_y.xml文件,里面包含y1-y480所对应的px值。由于需要适配的分辨率比较多,我们需要通过JAVA的文件输入输出流编写一个工具类来自动生成这些文件。该工具类需要生成主流分辨率的适配文件。并且考虑到可扩展性,main方法里需要接收args参数,这样用户在需要对一些特殊分辨率做适配时可以通过命令行的方式:java-jarxx.jarwidthheight来生成对用分辨率的适配文件,以此来完成对特殊分辨率的适配。Step 3: According to the above introduction, we need to generate an adaptation folder for each resolution to be adapted. The naming rule of the folder is valuse+adaptation resolution. For example, the folder name for adapting to 1920*1080 resolution is values-1920x1080. This folder contains two XML files, lay_x.xml contains the px value corresponding to x1-x320 and lay_y.xml file contains the px value corresponding to y1-y480. Since there are many resolutions that need to be adapted, we need to write a tool class to automatically generate these files through the file input and output stream of JAVA. This tool class needs to generate adaptation files for mainstream resolutions. And considering the scalability, the main method needs to receive the args parameter, so that when users need to adapt to some special resolutions, they can use the command line: java-jarxx.jarwidthheight to generate an adaptation file for the resolution , in order to complete the adaptation to the special resolution.

步骤4:根据Android系统的特性,如果一个Android应用的资源文件夹后缀中存在和运行当前应用的手机相同或者近似的分辨率数值,那么系统会优先使用该资源文件夹下的资源文件。所以在生成适配文件之后需要将这些文件加入到项目的res目录下,方便系统根据不同情况进行引用。Step 4: According to the characteristics of the Android system, if the resource folder suffix of an Android application has the same or similar resolution value as that of the mobile phone running the current application, the system will give priority to using the resource files in the resource folder. Therefore, after the adaptation files are generated, these files need to be added to the res directory of the project, so that the system can refer to them according to different situations.

步骤5:最后在编写布局文件时,通过使用dimen/x数值的方式来设置控件的宽高以及距离。如果UI设计的界面基于320*480,并且标注一个控件的长度为160px,则只需要将该控件的长度width设置为dimen/x160即可。在320*480的机器上会使用对应文件下的x160的值为160px为宽度的一半,而在1920*1080的机器上会使用values-1920x1080下的x160的值540px也为屏幕宽度的一半,其他分辨率以此类推。综上只要简单的使用设计图标注的px数值即可完成所有分辨率设备的适配。Step 5: Finally, when writing the layout file, set the width, height and distance of the control by using the dimen/x value. If the UI design interface is based on 320*480, and the length of a control is marked as 160px, you only need to set the length width of the control to dimen/x160. On a 320*480 machine, the x160 value of 160px under the corresponding file is used as half of the width, while on a 1920*1080 machine, the x160 value of 540px under values-1920x1080 is also half of the screen width, and others Resolution and so on. To sum up, simply use the px value marked on the design drawing to complete the adaptation of all resolution devices.

以上所述仅为本发明的一个具体实施例,并不用以限制本发明,凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The above description is only a specific embodiment of the present invention, and is not intended to limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included in the protection of the present invention. within range.

Claims (2)

1.一种基于百分比的Android手机屏幕适配方法,其特征在于包括以下步骤:1. a percentage-based Android mobile phone screen adaptation method is characterized in that comprising the following steps: 1)根据项目需求确定需要适配的手机屏幕分辨率;1) Determine the screen resolution of the mobile phone that needs to be adapted according to the project requirements; 2)以UI给出的设计图的分辨率为基准,将需要适配的手机屏幕分辨率在横向和纵向上以这个基准进行等分,并计算出在这个基准下一个单元的高度和宽度所分别对应的像素值px;2) Taking the resolution of the design drawing given by the UI as the benchmark, divide the screen resolution of the mobile phone to be adapted into equal parts horizontally and vertically with this benchmark, and calculate the height and width of a unit under this benchmark. The corresponding pixel value px respectively; 3)通过文件输入输出流的编程,实现自动生成适配文件的工具类,生成需要适配的分辨率所对应的values文件夹,以"values-需要适配的分辨率"的格式对该文件夹进行命名,该文件夹下包含两个文件,分别是记录屏幕宽度像素值和屏幕高度像素值的XML文件,这些像素值来自步骤2中的计算结果;3) Through the programming of file input and output streams, the tool class for automatically generating adaptation files is realized, and the values folder corresponding to the resolution to be adapted is generated, and the file is formatted in the format of "values-resolution to be adapted" Name the folder, which contains two files, which are XML files that record the screen width pixel value and screen height pixel value, and these pixel values come from the calculation results in step 2; 4)在编写布局文件时直接使用设计图上的px数值,即通过引用适配文件中对应数值的方式设置控件的属性和距离,系统会根据当前设备的分辨率到上述步骤3中生成的values文件夹中找到准确的像素值设置给控件,从而可以实现准确的适配。4) When writing the layout file, directly use the px value on the design drawing, that is, set the property and distance of the control by referencing the corresponding value in the adaptation file, and the system will use the resolution of the current device to the values generated in the above step 3 The exact pixel values found in the folder are set to the controls so that an accurate fit can be achieved. 2.根据权利要求1所述的一种基于百分比的Android手机屏幕适配方法,其特征在于如果需要适配一些特殊的分辨率,则通过命令行的方式将需要适配的特殊分辨率以参数的形式输入,生成需要适配分辨率的适配文件,然后根据Android系统的自适应特性,将这些适配文件夹加入Android项目的res目录下,最后执行步骤4,完成准确的适配。2. a kind of percentage-based Android mobile phone screen adaptation method according to claim 1 is characterized in that if some special resolutions need to be adapted, then the special resolution that needs to be adapted will be parameterized by the mode of command line Input in the form of , generate an adaptation file that needs to be adapted to the resolution, and then add these adaptation folders to the res directory of the Android project according to the adaptive characteristics of the Android system, and finally perform step 4 to complete the accurate adaptation.
CN201610164574.1A 2016-03-22 2016-03-22 Percentage-based Android mobile phone screen adaption method Pending CN105827833A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610164574.1A CN105827833A (en) 2016-03-22 2016-03-22 Percentage-based Android mobile phone screen adaption method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610164574.1A CN105827833A (en) 2016-03-22 2016-03-22 Percentage-based Android mobile phone screen adaption method

Publications (1)

Publication Number Publication Date
CN105827833A true CN105827833A (en) 2016-08-03

Family

ID=56524941

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610164574.1A Pending CN105827833A (en) 2016-03-22 2016-03-22 Percentage-based Android mobile phone screen adaption method

Country Status (1)

Country Link
CN (1) CN105827833A (en)

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107092479A (en) * 2017-03-17 2017-08-25 武汉斗鱼网络科技有限公司 Screen adaptation method and system for Android widescreen equipment
CN107980121A (en) * 2017-03-20 2018-05-01 深圳大趋智能科技有限公司 Circular self-defined control performs the method and device of animation
CN108415754A (en) * 2018-03-15 2018-08-17 万帮充电设备有限公司 Android UI adaptation methods and device
CN108984253A (en) * 2018-06-29 2018-12-11 奇酷互联网络科技(深圳)有限公司 Application Program Interface display methods, device, readable storage medium storing program for executing and mobile terminal
CN111338733A (en) * 2020-02-25 2020-06-26 珠海格力电器股份有限公司 User interface adaptation method and system
CN111708502A (en) * 2020-05-20 2020-09-25 北京明略软件系统有限公司 Screen adaptation method and device
CN111986601A (en) * 2020-07-13 2020-11-24 视联动力信息技术股份有限公司 Screen display method and device, terminal equipment and storage medium
CN112130840A (en) * 2020-07-31 2020-12-25 北京编程猫科技有限公司 An intelligent programming implementation method and device for obtaining the type of running equipment
CN114003241A (en) * 2020-07-28 2022-02-01 华为技术有限公司 Interface adaptation display method, system, electronic device and medium of application program

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2015226220A (en) * 2014-05-28 2015-12-14 京セラ株式会社 Mobile terminal and screen output method
CN105282321A (en) * 2015-08-28 2016-01-27 上海健保科技有限公司 Adaption method of application software user interface and display device

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2015226220A (en) * 2014-05-28 2015-12-14 京セラ株式会社 Mobile terminal and screen output method
CN105282321A (en) * 2015-08-28 2016-01-27 上海健保科技有限公司 Adaption method of application software user interface and display device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
赵凯强的博客: "Android屏幕适配全攻略(最权威的官方适配指导)", 《COCOA CHINA》 *

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107092479A (en) * 2017-03-17 2017-08-25 武汉斗鱼网络科技有限公司 Screen adaptation method and system for Android widescreen equipment
CN107980121A (en) * 2017-03-20 2018-05-01 深圳大趋智能科技有限公司 Circular self-defined control performs the method and device of animation
CN108415754A (en) * 2018-03-15 2018-08-17 万帮充电设备有限公司 Android UI adaptation methods and device
CN108984253A (en) * 2018-06-29 2018-12-11 奇酷互联网络科技(深圳)有限公司 Application Program Interface display methods, device, readable storage medium storing program for executing and mobile terminal
CN111338733A (en) * 2020-02-25 2020-06-26 珠海格力电器股份有限公司 User interface adaptation method and system
CN111708502A (en) * 2020-05-20 2020-09-25 北京明略软件系统有限公司 Screen adaptation method and device
CN111708502B (en) * 2020-05-20 2023-05-16 北京明略软件系统有限公司 Screen adaptation method and device
CN111986601A (en) * 2020-07-13 2020-11-24 视联动力信息技术股份有限公司 Screen display method and device, terminal equipment and storage medium
CN111986601B (en) * 2020-07-13 2024-03-29 视联动力信息技术股份有限公司 Screen display method, device, terminal equipment and storage medium
CN114003241A (en) * 2020-07-28 2022-02-01 华为技术有限公司 Interface adaptation display method, system, electronic device and medium of application program
CN112130840A (en) * 2020-07-31 2020-12-25 北京编程猫科技有限公司 An intelligent programming implementation method and device for obtaining the type of running equipment

Similar Documents

Publication Publication Date Title
CN105827833A (en) Percentage-based Android mobile phone screen adaption method
WO2018133663A1 (en) Page generation method, terminal, and data storage medium
WO2017113732A1 (en) Layout method and system for user interface control, and control method and system therefor
US20150227494A1 (en) Creating and editing dynamic graphics via a web interface
CN107239287A (en) A kind of Webpage display process, device, electronic equipment and storage medium
CN103955367A (en) Method and device for generating pages
JP2017526091A (en) Method, terminal and system for dynamically updating application interface
CN102662616A (en) Screen graphics self-adaption method and system used for mobile terminal
TW201807560A (en) Interface display method and apparatus
CN106354355A (en) User interface layout method, device and system
CN102298495A (en) Method for enabling android software to adapt to different screen densities
JP6501893B2 (en) Desktop sharing method and mobile terminal
CN102855315A (en) Cluster network topology presentation method based on HTML5 (HyperText Markup Language 5)
CN114281463B (en) Form interface format configuration and interface display method, device and medium
CN104598436A (en) Method and device for dynamically generating three-dimensional chart
CN105824517A (en) Implementation method and apparatus of desktop
CN105373545A (en) Picture display method and device
CN105045587A (en) Picture display method and apparatus
CN104506941A (en) Key event processing method and device in smart television
CN108419114A (en) A UI interface display method, device and storage medium for smart TV
CN106648700A (en) Display method and device compatible with different resolution ratios
CN107426588B (en) Method, system and storage device for acquiring television set configuration information
JP2013524375A (en) HD-WEB method for Internet content suitable for high resolution and any screen
CN113467738B (en) Screen adaptation method and device for display object, electronic device and storage medium
CN106201461A (en) Generation method, system and the background server at a kind of interface

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20160803

RJ01 Rejection of invention patent application after publication