File tree Expand file tree Collapse file tree
library/src/main/java/com/cds/library Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424##### 第一步:在你的项目的DimenTool.java文件中中注明你的设计稿的尺寸(设计稿尺寸请联系你们公司的美工确认哦!),并进行修改成你的设计图的尺寸
2525
2626```
27- //根据UI画布大小比例进行换算,UI图相对分辨率为1334x750(注意这里只注重设备的宽度)
28- int density = 2;//默认密度是160,设备默认密度是320,所以缩放因子是320/160
29- int width = 750 / density;
30-
31- //如果设计图尺寸为1080x1920,高分率设备一般密度较高,这种高分辨率密度一般为3,则:
32- density = 3;
33- width = 1080 / density;
27+ /**
28+ * 密度因子
29+ */
30+ int density;
31+ /**
32+ * 屏幕相对宽度
33+ */
34+ int width;
35+ /**
36+ * 1.根据UI画布大小比例进行换算,假设UI图分辨率为1334x750
37+ * 设备默认缩放因子密度为 density = 320 / 160 , 即 density = 2
38+ * 宽度 width = 750
39+ * 可选项,根据你实际的UI设计图来定义
40+ */
41+ density = 2;
42+ width = 750 / density;
43+ /**
44+ * 2.根据UI画布大小比例进行换算,假设UI图分辨率为1080x1920
45+ * 高分率缩放因子密度一般为 density = 80 / 160 , 即 density = 3
46+ * 宽度 width = 1080
47+ * 可选项,根据你实际的UI设计图来定义
48+ */
49+ density = 3;
50+ width = 1080 / density;
51+ /**
52+ * 执行生成适配的dimens.xml文件
53+ */
54+ gen(width);
3455```
3556
3657![ ] ( screenshot/pic20170514140636.png )
@@ -82,13 +103,13 @@ width = 1080 / density;
82103# License
83104
84105 Copyright 2016 cheng2016,Inc.
85-
106+
86107 Licensed under the Apache License, Version 2.0 (the "License");
87108 you may not use this file except in compliance with the License.
88109 You may obtain a copy of the License at
89-
110+
90111 http://www.apache.org/licenses/LICENSE-2.0
91-
112+
92113 Unless required by applicable law or agreed to in writing, software
93114 distributed under the License is distributed on an "AS IS" BASIS,
94115 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Original file line number Diff line number Diff line change @@ -23,26 +23,31 @@ public static void gen() {
2323 */
2424 int width ;
2525 /**
26- * 1.根据UI画布大小比例进行换算,假设UI图相对分辨率为1334x750
26+ * 1.根据UI画布大小比例进行换算,假设UI图分辨率为1334x750
2727 * 设备默认缩放因子密度为 density = 320 / 160 , 即 density = 2
2828 * 宽度 width = 750
2929 * 可选项,根据你实际的UI设计图来定义
3030 */
3131 density = 2 ;
3232 width = 750 / density ;
33-
3433 /**
35- * 2.根据UI画布大小比例进行换算,假设UI图相对分辨率为1080x1920
34+ * 2.根据UI画布大小比例进行换算,假设UI图分辨率为1080x1920
3635 * 高分率缩放因子密度一般为 density = 80 / 160 , 即 density = 3
3736 * 宽度 width = 1080
3837 * 可选项,根据你实际的UI设计图来定义
3938 */
4039 density = 3 ;
4140 width = 1080 / density ;
42-
41+ /**
42+ * 执行生成适配的dimens.xml文件
43+ */
4344 gen (width );
4445 }
4546
47+ /**
48+ * 生成对应的适配的dimens.xml文件
49+ * @param width
50+ */
4651 public static void gen (int width ) {
4752
4853 File file = new File ("./app/src/main/res/values/dimens.xml" );
You can’t perform that action at this time.
0 commit comments