UI design principle android 系统根据不同屏幕密度选择不同图片

Supporting Different Densities

支持不同密度

This lesson shows you how to support different screen densities by providing different resources and using resolution-independent units of measurements.

这一课 讲解使用不同资源文件夹下不同文件夹内的图片资源支持不同密度的手机

Use Density-independent Pixels 使用dp单位


One common pitfall you must avoid when designing your layouts is using absolute pixels to define distances or sizes. Defining layout dimensions with pixels is a problem because different screens have different pixel densities, so the same number of pixels may correspond to different physical sizes on different devices. Therefore, when specifying dimensions, always use either dp or sp units. A dp is a density-independent pixel that corresponds to the physical size of a pixel at 160 dpi. An sp is the same base unit, but is scaled by the user's preferred text size (it’s a scale-independent pixel), so you should use this measurement unit when defining text size (but never for layout sizes).

在我们设计布局的时候一个常见的误区我们要避免的就是使用绝对的像素单位来定义不同view之间的间距或者大小。因为不同大小的屏幕有着不一样的密度所以使用像素单位是有问题的。就是说 同样大小的一个像素值在不同密度屏幕上的显示的大小是不一样的。所以 使用dp 和sp 是必须的。dp 就是在160dpi上一像素对应1dp (dpi解释 dpi 是dot per inch 每英寸上像素数)dp单位是与像素无关的。sp是和dp一样的基本单位 但是sp是根据用户喜好的文字大小可以缩放的(是与像素无关可缩放的单位)。所以sp单位用来定义字体大小而不能用在布局大小上。

For example, when you specify spacing between two views, use dp rather than px:  举例说明 使用dp作为View之间的间距 而不同sp。

<Buttonandroid:layout_width="wrap_content" 

   
android:layout_height="wrap_content"
   
android:text="@string/clickme"
   
android:layout_marginTop="20dp"/>

When specifying text size, always use sp:  字体单位一律使用sp。

<TextViewandroid:layout_width="match_parent" 

   
android:layout_height="wrap_content"
   
android:textSize="20sp"/>

Provide Alternative Bitmaps 


Since Android runs in devices with a wide variety of screen densities, you should always provide your bitmap resources tailored to each of the generalized density buckets: low, medium, high and extra-high density. This will help you achieve good graphical quality and performance on all screen densities.

因为安卓系统运行在很多不同屏幕密度的手机上 我们应该提供  low, medium, high and extra-high 这4种不同的图片资源,android系统会根据屏幕密度从而自动选择对应的图片资源。

To generate these images, you should start with your raw resource in vector format and generate the images for each density using the following size scale:

 

  • xhdpi: 2.0
  • hdpi: 1.5
  • mdpi: 1.0 (baseline)
  • ldpi: 0.75

 

This means that if you generate a 200x200 image for xhdpi devices, you should generate the same resource in 150x150 for hdpi, 100x100 for mdpi and finally a 75x75 image for ldpi devices.

这意思是 如果你做了一个200x200的图片 适用xhdpi的手机 那么 我们就需要制作 150x150 for hdpi, 100x100 for mdpi  一句话就是 200x200 是适用密度为2.0,150x150 for hdpi 是密度为1.5 100x100 for mdpi  1.0

Then, place the generated image files in the appropriate subdirectory under res/ and the system will pick the correct one automatically based on the screen density of the device your application is running on: 然后 把这些不同图片放到下面的文件夹中 程序运行时系统会自动根据实际设备的密度使用对应的图片资源。

MyProject/
  res/
    drawable-xhdpi/
        awesomeimage.png
    drawable-hdpi/
        awesomeimage.png
    drawable-mdpi/
        awesomeimage.png
    drawable-ldpi/
        awesomeimage.png

Then, any time you reference @drawable/awesomeimage, the system selects the appropriate bitmap based on the screen's dpi.

For more tips and guidelines for creating icon assets for your application, see the Icon Design Guidelines. icon设计指导:

 

Icon Design Guidelines   地址: http://developer.android.com/guide/practices/ui_guidelines/icon_design.html

设计者的新红宝书 里边的是关于设计的 包括 actionbar listView里边的子View的设计 等等 很专业。 

现在引入 另外一个人的博客 讲的更加详细 请参考 http://blog.sina.com.cn/s/blog_865366f801018w6k.html

 

 

 

 

 

转载于:https://www.cnblogs.com/proudToBeAITeer/archive/2013/03/23/2977535.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值