Android 厘米转dip、px转dip 地图比例尺长度计算

主要解决问题:

  1.Android各个长度单位转换为px(px、dip、mm等)

  2.px和dip的转换

使用的工具类:

  1.Android-API-工具类:TypedValue.applyDimension(int unit, float value,DisplayMetrics metrics);(大家最好读下附件中的TypedValue类源码)

  参数说明:

      (1)unit:输入值的类型(px、dip、mm、sp等)

      (2)value:对应的值

      (3)metrics:DisplayMetrics,

        DisplayMetrics官方解释:A structure describing general information about a display, such as its size, density, and font scaling.

      获取方法1:

      DisplayMetrics metrics = new DisplayMetrics();

      getWindowManager().getDefaultDisplay().getMetrics(metrics)

      获取方法2:

      context.getResources().getDisplayMetrics();

    详细介绍参见:

      http://www.eoeandroid.com/thread-246188-1-1.html

  2.DensityUtil类

    提供了px和dip的互转方法

    转自:http://blog.csdn.net/arui319/article/details/6777133

备注:

  有兴趣的朋友可以再封装下发布

附件:

  Android.util.TypedValue类源码如下:

  1 /*
  2  * Copyright (C) 2007 The Android Open Source Project
  3  *
  4  * Licensed under the Apache License, Version 2.0 (the "License");
  5  * you may not use this file except in compliance with the License.
  6  * You may obtain a copy of the License at
  7  *
  8  *      http://www.apache.org/licenses/LICENSE-2.0
  9  *
 10  * Unless required by applicable law or agreed to in writing, software
 11  * distributed under the License is distributed on an "AS IS" BASIS,
 12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  * See the License for the specific language governing permissions and
 14  * limitations under the License.
 15  */
 16
 17 package android.util;
 18
 19 /**
 20  * Container for a dynamically typed data value.  Primarily used with
 21  * {@link android.content.res.Resources} for holding resource values.
 22  */
 23 public class TypedValue {
 24     /** The value contains no data. */
 25     public static final int TYPE_NULL = 0x00;
 26
 27     /** The <var>data</var> field holds a resource identifier. */
 28     public static final int TYPE_REFERENCE = 0x01;
 29     /** The <var>data</var> field holds an attribute resource
 30      *  identifier (referencing an attribute in the current theme
 31      *  style, not a resource entry). */
 32     public static final int TYPE_ATTRIBUTE = 0x02;
 33     /** The <var>string</var> field holds string data.  In addition, if
 34      *  <var>data</var> is non-zero then it is the string block
 35      *  index of the string and <var>assetCookie</var> is the set of
 36      *  assets the string came from. */
 37     public static final int TYPE_STRING = 0x03;
 38     /** The <var>data</var> field holds an IEEE 754 floating point number. */
 39     public static final int TYPE_FLOAT = 0x04;
 40     /** The <var>data</var> field holds a complex number encoding a
 41      *  dimension value. */
 42     public static final int TYPE_DIMENSION = 0x05;
 43     /** The <var>data</var> field holds a complex number encoding a fraction
 44      *  of a container. */
 45     public static final int TYPE_FRACTION = 0x06;
 46
 47     /** Identifies the start of plain integer values.  Any type value
 48      *  from this to {@link #TYPE_LAST_INT} means the
 49      *  <var>data</var> field holds a generic integer value. */
 50     public static final int TYPE_FIRST_INT = 0x10;
 51
 52     /** The <var>data</var> field holds a number that was
 53      *  originally specified in decimal. */
 54     public static final int TYPE_INT_DEC = 0x10;
 55     /** The <var>data</var> field holds a number that was
 56      *  originally specified in hexadecimal (0xn). */
 57     public static final int TYPE_INT_HEX = 0x11;
 58     /** The <var>data</var> field holds 0 or 1 that was originally
 59      *  specified as "false" or "true". */
 60     public static final int TYPE_INT_BOOLEAN = 0x12;
 61
 62     /** Identifies the start of integer values that were specified as
 63      *  color constants (starting with ‘#‘). */
 64     public static final int TYPE_FIRST_COLOR_INT = 0x1c;
 65
 66     /** The <var>data</var> field holds a color that was originally
 67      *  specified as #aarrggbb. */
 68     public static final int TYPE_INT_COLOR_ARGB8 = 0x1c;
 69     /** The <var>data</var> field holds a color that was originally
 70      *  specified as #rrggbb. */
 71     public static final int TYPE_INT_COLOR_RGB8 = 0x1d;
 72     /** The <var>data</var> field holds a color that was originally
 73      *  specified as #argb. */
 74     public static final int TYPE_INT_COLOR_ARGB4 = 0x1e;
 75     /** The <var>data</var> field holds a color that was originally
 76      *  specified as #rgb. */
 77     public static final int TYPE_INT_COLOR_RGB4 = 0x1f;
 78
 79     /** Identifies the end of integer values that were specified as color
 80      *  constants. */
 81     public static final int TYPE_LAST_COLOR_INT = 0x1f;
 82
 83     /** Identifies the end of plain integer values. */
 84     public static final int TYPE_LAST_INT = 0x1f;
 85
 86     /* ------------------------------------------------------------ */
 87
 88     /** Complex data: bit location of unit information. */
 89     public static final int COMPLEX_UNIT_SHIFT = 0;
 90     /** Complex data: mask to extract unit information (after shifting by
 91      *  {@link #COMPLEX_UNIT_SHIFT}). This gives us 16 possible types, as
 92      *  defined below. */
 93     public static final int COMPLEX_UNIT_MASK = 0xf;
 94
 95     /** {@link #TYPE_DIMENSION} complex unit: Value is raw pixels. */
 96     public static final int COMPLEX_UNIT_PX = 0;
 97     /** {@link #TYPE_DIMENSION} complex unit: Value is Device Independent
 98      *  Pixels. */
 99     public static final int COMPLEX_UNIT_DIP = 1;
100     /** {@link #TYPE_DIMENSION} complex unit: Value is a scaled pixel. */
101     public static final int COMPLEX_UNIT_SP = 2;
102     /** {@link #TYPE_DIMENSION} complex unit: Value is in points. */
103     public static final int COMPLEX_UNIT_PT = 3;
104     /** {@link #TYPE_DIMENSION} complex unit: Value is in inches. */
105     public static final int COMPLEX_UNIT_IN = 4;
106     /** {@link #TYPE_DIMENSION} complex unit: Value is in millimeters. */
107     public static final int COMPLEX_UNIT_MM = 5;
108
109     /** {@link #TYPE_FRACTION} complex unit: A basic fraction of the overall
110      *  size. */
111     public static final int COMPLEX_UNIT_FRACTION = 0;
112     /** {@link #TYPE_FRACTION} complex unit: A fraction of the parent size. */
113     public static final int COMPLEX_UNIT_FRACTION_PARENT = 1;
114
115     /** Complex data: where the radix information is, telling where the decimal
116      *  place appears in the mantissa. */
117     public static final int COMPLEX_RADIX_SHIFT = 4;
118     /** Complex data: mask to extract radix information (after shifting by
119      * {@link #COMPLEX_RADIX_SHIFT}). This give us 4 possible fixed point
120      * representations as defined below. */
121     public static final int COMPLEX_RADIX_MASK = 0x3;
122
123     /** Complex data: the mantissa is an integral number -- i.e., 0xnnnnnn.0 */
124     public static final int COMPLEX_RADIX_23p0 = 0;
125     /** Complex data: the mantissa magnitude is 16 bits -- i.e, 0xnnnn.nn */
126     public static final int COMPLEX_RADIX_16p7 = 1;
127     /** Complex data: the mantissa magnitude is 8 bits -- i.e, 0xnn.nnnn */
128     public static final int COMPLEX_RADIX_8p15 = 2;
129     /** Complex data: the mantissa magnitude is 0 bits -- i.e, 0x0.nnnnnn */
130     public static final int COMPLEX_RADIX_0p23 = 3;
131
132     /** Complex data: bit location of mantissa information. */
133     public static final int COMPLEX_MANTISSA_SHIFT = 8;
134     /** Complex data: mask to extract mantissa information (after shifting by
135      *  {@link #COMPLEX_MANTISSA_SHIFT}). This gives us 23 bits of precision;
136      *  the top bit is the sign. */
137     public static final int COMPLEX_MANTISSA_MASK = 0xffffff;
138
139     /* ------------------------------------------------------------ */
140
141     /**
142      * If {@link #density} is equal to this value, then the density should be
143      * treated as the system‘s default density value: {@link DisplayMetrics#DENSITY_DEFAULT}.
144      */
145     public static final int DENSITY_DEFAULT = 0;
146
147     /**
148      * If {@link #density} is equal to this value, then there is no density
149      * associated with the resource and it should not be scaled.
150      */
151     public static final int DENSITY_NONE = 0xffff;
152
153     /* ------------------------------------------------------------ */
154
155     /** The type held by this value, as defined by the constants here.
156      *  This tells you how to interpret the other fields in the object. */
157     public int type;
158
159     /** If the value holds a string, this is it. */
160     public CharSequence string;
161
162     /** Basic data in the value, interpreted according to {@link #type} */
163     public int data;
164
165     /** Additional information about where the value came from; only
166      *  set for strings. */
167     public int assetCookie;
168
169     /** If Value came from a resource, this holds the corresponding resource id. */
170     public int resourceId;
171
172     /** If Value came from a resource, these are the configurations for which
173      *  its contents can change. */
174     public int changingConfigurations = -1;
175
176     /**
177      * If the Value came from a resource, this holds the corresponding pixel density.
178      * */
179     public int density;
180
181     /* ------------------------------------------------------------ */
182
183     /** Return the data for this value as a float.  Only use for values
184      *  whose type is {@link #TYPE_FLOAT}. */
185     public final float getFloat() {
186         return Float.intBitsToFloat(data);
187     }
188
189     private static final float MANTISSA_MULT =
190         1.0f / (1<<TypedValue.COMPLEX_MANTISSA_SHIFT);
191     private static final float[] RADIX_MULTS = new float[] {
192         1.0f*MANTISSA_MULT, 1.0f/(1<<7)*MANTISSA_MULT,
193         1.0f/(1<<15)*MANTISSA_MULT, 1.0f/(1<<23)*MANTISSA_MULT
194     };
195
196     /**
197      * Retrieve the base value from a complex data integer.  This uses the
198      * {@link #COMPLEX_MANTISSA_MASK} and {@link #COMPLEX_RADIX_MASK} fields of
199      * the data to compute a floating point representation of the number they
200      * describe.  The units are ignored.
201      *
202      * @param complex A complex data value.
203      *
204      * @return A floating point value corresponding to the complex data.
205      */
206     public static float complexToFloat(int complex)
207     {
208         return (complex&(TypedValue.COMPLEX_MANTISSA_MASK
209                    <<TypedValue.COMPLEX_MANTISSA_SHIFT))
210             * RADIX_MULTS[(complex>>TypedValue.COMPLEX_RADIX_SHIFT)
211                             & TypedValue.COMPLEX_RADIX_MASK];
212     }
213
214     /**
215      * Converts a complex data value holding a dimension to its final floating
216      * point value. The given <var>data</var> must be structured as a
217      * {@link #TYPE_DIMENSION}.
218      *
219      * @param data A complex data value holding a unit, magnitude, and
220      *             mantissa.
221      * @param metrics Current display metrics to use in the conversion --
222      *                supplies display density and scaling information.
223      *
224      * @return The complex floating point value multiplied by the appropriate
225      * metrics depending on its unit.
226      */
227     public static float complexToDimension(int data, DisplayMetrics metrics)
228     {
229         return applyDimension(
230             (data>>COMPLEX_UNIT_SHIFT)&COMPLEX_UNIT_MASK,
231             complexToFloat(data),
232             metrics);
233     }
234
235     /**
236      * Converts a complex data value holding a dimension to its final value
237      * as an integer pixel offset.  This is the same as
238      * {@link #complexToDimension}, except the raw floating point value is
239      * truncated to an integer (pixel) value.
240      * The given <var>data</var> must be structured as a
241      * {@link #TYPE_DIMENSION}.
242      *
243      * @param data A complex data value holding a unit, magnitude, and
244      *             mantissa.
245      * @param metrics Current display metrics to use in the conversion --
246      *                supplies display density and scaling information.
247      *
248      * @return The number of pixels specified by the data and its desired
249      * multiplier and units.
250      */
251     public static int complexToDimensionPixelOffset(int data,
252             DisplayMetrics metrics)
253     {
254         return (int)applyDimension(
255                 (data>>COMPLEX_UNIT_SHIFT)&COMPLEX_UNIT_MASK,
256                 complexToFloat(data),
257                 metrics);
258     }
259
260     /**
261      * Converts a complex data value holding a dimension to its final value
262      * as an integer pixel size.  This is the same as
263      * {@link #complexToDimension}, except the raw floating point value is
264      * converted to an integer (pixel) value for use as a size.  A size
265      * conversion involves rounding the base value, and ensuring that a
266      * non-zero base value is at least one pixel in size.
267      * The given <var>data</var> must be structured as a
268      * {@link #TYPE_DIMENSION}.
269      *
270      * @param data A complex data value holding a unit, magnitude, and
271      *             mantissa.
272      * @param metrics Current display metrics to use in the conversion --
273      *                supplies display density and scaling information.
274      *
275      * @return The number of pixels specified by the data and its desired
276      * multiplier and units.
277      */
278     public static int complexToDimensionPixelSize(int data,
279             DisplayMetrics metrics)
280     {
281         final float value = complexToFloat(data);
282         final float f = applyDimension(
283                 (data>>COMPLEX_UNIT_SHIFT)&COMPLEX_UNIT_MASK,
284                 value,
285                 metrics);
286         final int res = (int)(f+0.5f);
287         if (res != 0) return res;
288         if (value == 0) return 0;
289         if (value > 0) return 1;
290         return -1;
291     }
292
293     public static float complexToDimensionNoisy(int data, DisplayMetrics metrics)
294     {
295         float res = complexToDimension(data, metrics);
296         System.out.println(
297             "Dimension (0x" + ((data>>TypedValue.COMPLEX_MANTISSA_SHIFT)
298                                & TypedValue.COMPLEX_MANTISSA_MASK)
299             + "*" + (RADIX_MULTS[(data>>TypedValue.COMPLEX_RADIX_SHIFT)
300                                 & TypedValue.COMPLEX_RADIX_MASK] / MANTISSA_MULT)
301             + ")" + DIMENSION_UNIT_STRS[(data>>COMPLEX_UNIT_SHIFT)
302                                 & COMPLEX_UNIT_MASK]
303             + " = " + res);
304         return res;
305     }
306
307     /**
308      * Converts an unpacked complex data value holding a dimension to its final floating
309      * point value. The two parameters <var>unit</var> and <var>value</var>
310      * are as in {@link #TYPE_DIMENSION}.
311      *
312      * @param unit The unit to convert from.
313      * @param value The value to apply the unit to.
314      * @param metrics Current display metrics to use in the conversion --
315      *                supplies display density and scaling information.
316      *
317      * @return The complex floating point value multiplied by the appropriate
318      * metrics depending on its unit.
319      */
320     public static float applyDimension(int unit, float value,
321                                        DisplayMetrics metrics)
322     {
323         switch (unit) {
324         case COMPLEX_UNIT_PX:
325             return value;
326         case COMPLEX_UNIT_DIP:
327             return value * metrics.density;
328         case COMPLEX_UNIT_SP:
329             return value * metrics.scaledDensity;
330         case COMPLEX_UNIT_PT:
331             return value * metrics.xdpi * (1.0f/72);
332         case COMPLEX_UNIT_IN:
333             return value * metrics.xdpi;
334         case COMPLEX_UNIT_MM:
335             return value * metrics.xdpi * (1.0f/25.4f);
336         }
337         return 0;
338     }
339
340     /**
341      * Return the data for this value as a dimension.  Only use for values
342      * whose type is {@link #TYPE_DIMENSION}.
343      *
344      * @param metrics Current display metrics to use in the conversion --
345      *                supplies display density and scaling information.
346      *
347      * @return The complex floating point value multiplied by the appropriate
348      * metrics depending on its unit.
349      */
350     public float getDimension(DisplayMetrics metrics)
351     {
352         return complexToDimension(data, metrics);
353     }
354
355     /**
356      * Converts a complex data value holding a fraction to its final floating
357      * point value. The given <var>data</var> must be structured as a
358      * {@link #TYPE_FRACTION}.
359      *
360      * @param data A complex data value holding a unit, magnitude, and
361      *             mantissa.
362      * @param base The base value of this fraction.  In other words, a
363      *             standard fraction is multiplied by this value.
364      * @param pbase The parent base value of this fraction.  In other
365      *             words, a parent fraction (nn%p) is multiplied by this
366      *             value.
367      *
368      * @return The complex floating point value multiplied by the appropriate
369      * base value depending on its unit.
370      */
371     public static float complexToFraction(int data, float base, float pbase)
372     {
373         switch ((data>>COMPLEX_UNIT_SHIFT)&COMPLEX_UNIT_MASK) {
374         case COMPLEX_UNIT_FRACTION:
375             return complexToFloat(data) * base;
376         case COMPLEX_UNIT_FRACTION_PARENT:
377             return complexToFloat(data) * pbase;
378         }
379         return 0;
380     }
381
382     /**
383      * Return the data for this value as a fraction.  Only use for values whose
384      * type is {@link #TYPE_FRACTION}.
385      *
386      * @param base The base value of this fraction.  In other words, a
387      *             standard fraction is multiplied by this value.
388      * @param pbase The parent base value of this fraction.  In other
389      *             words, a parent fraction (nn%p) is multiplied by this
390      *             value.
391      *
392      * @return The complex floating point value multiplied by the appropriate
393      * base value depending on its unit.
394      */
395     public float getFraction(float base, float pbase)
396     {
397         return complexToFraction(data, base, pbase);
398     }
399
400     /**
401      * Regardless of the actual type of the value, try to convert it to a
402      * string value.  For example, a color type will be converted to a
403      * string of the form #aarrggbb.
404      *
405      * @return CharSequence The coerced string value.  If the value is
406      *         null or the type is not known, null is returned.
407      */
408     public final CharSequence coerceToString()
409     {
410         int t = type;
411         if (t == TYPE_STRING) {
412             return string;
413         }
414         return coerceToString(t, data);
415     }
416
417     private static final String[] DIMENSION_UNIT_STRS = new String[] {
418         "px", "dip", "sp", "pt", "in", "mm"
419     };
420     private static final String[] FRACTION_UNIT_STRS = new String[] {
421         "%", "%p"
422     };
423
424     /**
425      * Perform type conversion as per {@link #coerceToString()} on an
426      * explicitly supplied type and data.
427      *
428      * @param type The data type identifier.
429      * @param data The data value.
430      *
431      * @return String The coerced string value.  If the value is
432      *         null or the type is not known, null is returned.
433      */
434     public static final String coerceToString(int type, int data)
435     {
436         switch (type) {
437         case TYPE_NULL:
438             return null;
439         case TYPE_REFERENCE:
440             return "@" + data;
441         case TYPE_ATTRIBUTE:
442             return "?" + data;
443         case TYPE_FLOAT:
444             return Float.toString(Float.intBitsToFloat(data));
445         case TYPE_DIMENSION:
446             return Float.toString(complexToFloat(data)) + DIMENSION_UNIT_STRS[
447                 (data>>COMPLEX_UNIT_SHIFT)&COMPLEX_UNIT_MASK];
448         case TYPE_FRACTION:
449             return Float.toString(complexToFloat(data)*100) + FRACTION_UNIT_STRS[
450                 (data>>COMPLEX_UNIT_SHIFT)&COMPLEX_UNIT_MASK];
451         case TYPE_INT_HEX:
452             return "0x" + Integer.toHexString(data);
453         case TYPE_INT_BOOLEAN:
454             return data != 0 ? "true" : "false";
455         }
456
457         if (type >= TYPE_FIRST_COLOR_INT && type <= TYPE_LAST_COLOR_INT) {
458             return "#" + Integer.toHexString(data);
459         } else if (type >= TYPE_FIRST_INT && type <= TYPE_LAST_INT) {
460             return Integer.toString(data);
461         }
462
463         return null;
464     }
465
466     public void setTo(TypedValue other)
467     {
468         type = other.type;
469         string = other.string;
470         data = other.data;
471         assetCookie = other.assetCookie;
472         resourceId = other.resourceId;
473         density = other.density;
474     }
475
476     public String toString()
477     {
478         StringBuilder sb = new StringBuilder();
479         sb.append("TypedValue{t=0x").append(Integer.toHexString(type));
480         sb.append("/d=0x").append(Integer.toHexString(data));
481         if (type == TYPE_STRING) {
482             sb.append(" \"").append(string != null ? string : "<null>").append("\"");
483         }
484         if (assetCookie != 0) {
485             sb.append(" a=").append(assetCookie);
486         }
487         if (resourceId != 0) {
488             sb.append(" r=0x").append(Integer.toHexString(resourceId));
489         }
490         sb.append("}");
491         return sb.toString();
492     }
493 };

Android.util.TypedValue

  自定义DensityUtil类

  说明:+0.5f的原因:根据网上的说法是为了保证结果不小于0.

 1 /**
 2      * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
 3      */
 4     public static int dip2px(Context context, float dpValue) {
 5         final float scale = context.getResources().getDisplayMetrics().density;
 6         return (int) (dpValue * scale + 0.5f);
 7     }
 8
 9     /**
10      * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
11      */
12     public static int px2dip(Context context, float pxValue) {
13         final float scale = context.getResources().getDisplayMetrics().density;
14         return (int) (pxValue / scale + 0.5f);
15     }
时间: 2024-11-11 18:39:58

Android 厘米转dip、px转dip 地图比例尺长度计算的相关文章

31.Android之常用单位px、dip、sp学习

一.  概述 我们在页面布局的时候,经常会设置容器的长度,但是到底该使用哪个作为长度的单位而懊恼. 在Android中支持的描述大小区域的类型有以下几种. px(pixels)——像素:不同的设备显示效果相同,一般我们HVGA代表320x480像素,这个用的比较多. dip(device independent pixels)——设备独立像素:这个和设备硬件有关,一般哦我们为了支持WCGA.HVGA和QVGA推荐使用这个,不依赖于像素.等同于dp. sp(scaled pixels—best f

Android之——屏幕适配px转dip

转载请注明出处:http://blog.csdn.net/l1028386804/article/details/47356583 做过Android开发的童鞋都知道,由于Android手机屏幕的多样性,要想自己写的应用程序能够在不同屏幕的Android手机上运行良好,那就要涉及到屏幕的适配问题了.很多时候,团队中的美工人员给出的设计图往往都是以px为单位的,我们直接以px为单位来使用的时候,往往会出现屏幕适配的问题.Android官方文档中给出控件的长宽最好是使用dip为单位,而接界面文字的大

Android - 开发页面需了解的dip,sp,px知识,以及它们之间的转换

工作中,时常会有任务要求开发新页面,这时一般的流程是产品经理确定要开发的页面和功能,然后设计师提供设计稿,之后由我们开发人员完成开发工作. 通常,设计师提供的设计稿尺寸标注会很详细,例如涉及到字时,字的大小,位置,颜色,字体等,都会一一标注.这时注意的是,设计师提供的尺寸标注全部是px(像素)为单位. 但我们在开发时不能直接使用px,按照Android规范,间距需使用dip(dp),字体大小需使用sp. 这时就需要我们做出px与dip(dp),sp的转换. 一. 了解dip(dp),sp,px

在Android中,px,dp,dip,sp的不同之处

       最近在学习Android开发,一直没有弄清楚px,dp,dip,sp的区别.今天正好有时间,就花时间研究了一下.     众所周知,Android厂商非常多,各种尺寸的Android手机.平板层出不穷.导致了Android生态环境的碎片化现象越来越严重.Google公司为了解决分辨率过多的问题,在Android的开发文档中定义了px,dp,dip,sp,方便开发者适配不同分辨率的Android设备. 1.基础知识:     mm:millimeters 毫米,长度单位.     i

Android屏幕分辨率概念(dp、dip、dpi、sp、px)

1.屏幕尺寸(screen size)就是我们平常讲的手机屏幕大小,是屏幕的对角线长度,一般讲的大小单位都是英寸.比如iPhone5S的屏幕尺寸是4英寸.Samsung Note3是5.7英寸. 2.像素(pixel)想像把屏幕放大再放大,对!看到的那一个个小点或者小方块就是像素了. 3.分辨率(Resolution)是指屏幕上垂直方向和水平方向上的像素个数.比如iPhone5S的分辨率是1136*640:Samsung Note3的分辨率是1920*1080: 4.dpi是dot per in

[转]Android中px dpi dip density densityDpi 的相关说明

概念解释 名词 解释 Px (Pixel像素) 不同设备显示效果相同.这里的“相同”是指像素数不会变,比如指定UI长度是100px,那不管分辨率是多少UI长度都是100px.也正是因为如此才造成了UI在小分辨率设备上被放大而失真,在大分辨率上被缩小. Screen Size (屏幕尺寸) 一般所说的手机屏幕大小如1.6英寸.1.9英寸.2.2英寸,都是指的对角线的长度,而不是手机面积.我们可以根据勾股定理获取手机的宽和长,当然还有面积. Resolution (分辨率) 指手机屏幕垂直和水平方向

设计师给了px单位的标注,Android开发到底要设置多少dip、dp、sp?

本文链接    http://blog.csdn.net/xiaodongrush/article/details/29560431 1. 要开发一款Android APP,设计师和开发要约定哪些事情? 首先,选择一款主流机型. 然后,设计师根据该机型的屏幕尺寸设计效果图,给出px单位的标注. 最后,开发根据该机型,可以算出px与dp的换算方法,根据px单位的标注,设置为dp为单位的标注. 备注:1dp=1dip=1sp,对于一般长宽dp或者dip都可以,sp是字体专用单位,在操作系统中设置大中

Android中px dpi dip density densityDpi 的相关说明

概念解释 名词 解释 Px (Pixel像素) 不同设备显示效果相同.这里的“相同”是指像素数不会变,比如指定UI长度是100px,那不管分辨率是多少UI长度都是100px.也正是因为如此才造成了UI在小分辨率设备上被放大而失真,在大分辨率上被缩小. Screen Size (屏幕尺寸) 一般所说的手机屏幕大小如1.6英寸.1.9英寸.2.2英寸,都是指的对角线的长度,而不是手机面积.我们可以根据勾股定理获取手机的宽和长,当然还有面积. Resolution (分辨率) 指手机屏幕垂直和水平方向

Android的px、dip、sp的区别

Android的px.dip.sp的区别 我们在页面布局的时候,经常会设置容器的长度,但是到底该使用哪个作为长度的单位而懊恼. 在Android中支持的描述大小区域的类型有以下几种: px(pixels)——像素:不同的设备显示效果相同,一般我们HVGA代表320x480像素,这个用的比较多. dip(device independent pixels)——设备独立像素:这个和设备硬件有关,一般哦我们为了支持WCGA.HVGA和QVGA推荐使用这个,不依赖于像素.等同于dp.是一种与密度无关的像