我们需要用不同的DPI到Android应用程序添加的所有图片 [英] Do we need to add all images with different dpi to Android Apps

查看:154
本文介绍了我们需要用不同的DPI到Android应用程序添加的所有图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如你所知道的Andr​​oid应用程序有不同的DPI,并在Android应用中,我们可以添加绘制取值均拥有不同的DPI在不同势 LDPI MDPI 华电国际 xhdpi 文件夹

As you know Android applications have different DPIs and also in the Android applications we can add drawables with diffrent DPIs in diffrent ldpi, mdpi, hdpi and xhdpi folders.

现在的问题是,当我们希望支持所有的干粉吸入器,我们应该与所有不同尺寸或只是一个最大的添加图标

The question is that when we want to support all DPIs we should add the icons with all different sizes or just with the biggest one?

我的意思是比如假设我有一个动作栏项目的图标。我是否应该加入这个动作栏项目的24x24的图标(在绘制-MDPI文件夹),36x36的(在drawble - 华电国际文件夹),48×48(在绘制-xhdpi文件夹),......

I mean for example suppose that I have one action bar item with icon. Whether I should add the icon of this action bar item with 24x24(in drawable-mdpi folder),36x36 (in drawble-hdpi folder),48x48 (in drawable-xhdpi folder),.....

或者,我只需要添加与尺寸96×96一个图标 xxxhdpi 文件夹,Android将设置图标为其他DPI的质量好?

Or I just need to add one icon with size 96x96 in xxxhdpi folder and android will set the icon for other DPIs with good quality?

推荐答案

TLDR看到下面的粗体

不同密度的文件夹添加以后为Android,这意味着...

Different density folders were added later on for Android which means that...

如果你想偷懒,只需添加一个资产的最佳选择很可能是在华电国际的资产,如果您的分应用目标和LT; 8 XHDPI 如果> = 8 。这是因为系统将扩大资源上下,但你仍然希望以尽可能高的分辨率的开始。

If you wanted to be lazy and just add one asset the best choice would probably be the HDPI asset if your min app target < 8 and XHDPI if its >= 8. This is because the system will scale the resource up and down, but you would still want to start off with the highest resolution possible.

在实践中我一般都提供华电国际/ XHDPI如前,把所有的资源桶喜欢的事情徽标/ AB图标/应用程序图标等等。总的来说,我发现自动缩放,pretty的好和工作在大多数情况下,但偶尔有供应和额外的LD / MD资产如果一个小的资产/包含小文等。另外,如果我复制的所有资产,像XXXHDPI我会得到pretty的好APK膨胀。

您还可以使用内置的工具,IDE来一次添加一个单一资产为许多densitys。在机器人工作室0.6,这是文件 - >新建 - >图像资产和向导将会出现。

You can also use IDEs built in tools to add a single asset for many densitys at once. In Android Studio 0.6 this is File->New->Image Asset and a wizard will appear.

我从来没有看到或听到的,允许Android的自动缩放资产的任何性能比较影响 - presumably这是在硬件完成

I have never noticed or heard of any perfomance impact of allowing Android to scale assets automatically - presumably this is done in hardware.

这可能不是很好看的时候自动缩放到LDPI这么说,你可以选择提供自己的缩放资产所有其它密度。

It may not look great when auto scaling down to LDPI say so you can optionally provide your own scaled assets for all other densities.

从链接采取以下

  • LDPI:低密度屏幕;约120DPI。
  • MDPI:中密度(在传统的HVGA)的屏幕;约160dpi。
  • 华电国际:高密度的屏幕;约240dpi。
  • xhdpi:超高密度显示屏;大约320dpi。 添加在API级别8
  • nodpi:这可以用于那些不希望被缩放以匹配器件密度的位图的资源
  • tvdpi:屏幕MDPI和HDPI介于两者之间;大约213dpi。这不被认为是主密度组。它主要用于电视和大多数应用程序不应该需要它,提供MDPI和华电国际的资源足以满足大多数应用程序,系统将扩展他们适当的。此预选赛中引入了 API级别13。
  • ldpi: Low-density screens; approximately 120dpi.
  • mdpi: Medium-density (on traditional HVGA) screens; approximately 160dpi.
  • hdpi: High-density screens; approximately 240dpi.
  • xhdpi: Extra high-density screens; approximately 320dpi. Added in API Level 8
  • nodpi: This can be used for bitmap resources that you do not want to be scaled to match the device density.
  • tvdpi: Screens somewhere between mdpi and hdpi; approximately 213dpi. This is not considered a "primary" density group. It is mostly intended for televisions and most apps shouldn't need it—providing mdpi and hdpi resources is sufficient for most apps and the system will scale them as appropriate. This qualifier was introduced with API level 13.

从<一个拍摄列表href="http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources"相对=nofollow>这个开发链接了解更多信息。

List taken from this dev link for more info.

这是我在我的职业生涯,包括那些为谷歌和放大器用于许多应用程序的方法; BBC和没有问题的。

This is the approach I have used on many apps in my professional career including ones for Google & the BBC and not had issues.

这篇关于我们需要用不同的DPI到Android应用程序添加的所有图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆