如何创建好看的绘图。
对于我的应用程序,我需要几个小图标。我将它们以 15dp * 15dp 的大小放在布局 xml 文件中。问题是它们在设备上看起来不太好。如果我看一下标准的 android 图标,例如刷新图标,它们看起来非常清晰。
我所做的是,我用 Gimp 创建了一个 15*15 像素的图像并尝试使用它。我想这不是一个好方法,因为 15dp != 15 px,对吗?创建漂亮、好看的图标(即使它们需要很小)的通常工作流程是什么?
For my app I need several small icons. I put them at a size of 15dp * 15dp in the layout xml file. The problem is that they do not look good on the device. If I look at the standard android Icons, e.g. for refresh, they look very sharp.
What I did was, I created a 15*15 pixel image with Gimp and tried to use it. I guess that is not a good approach since 15dp != 15 px, right? What is the usual workflow for creating nice, good looking icons, even if they need to be small?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
与密度无关的像素(即 XML 中的
dip
或dp
)旨在通过缩放 UI 以在每个设备上看起来大致相同的大小来跨设备提供更一致的视觉外观。这与物理尺寸缩放并不完全相同,而是屏幕的像素密度(dpi)。任何设备基本上都可以分为四个类别(ldpi、mdpi、hdpi、xhdpi)。dp
单位是根据 mdpi 建模的,所有其他存储桶都是从那里开始的比例因子。换句话说,15dp 在 mdpi 设备上等于 15px,但在其他设备上则不然。为了获得最佳性能,您需要做的是创建四种尺寸的图标,并将它们放置在相应的
drawable/
目录中。例如,对于 15dp 图标,您应该具有:该应用程序将获取适当的资源以匹配您正在运行的设备的分辨率。如果您没有为每个级别创建资产,应用程序将采用最接近的匹配并将其放大或缩小(您可能正在使用 HDPI 设备进行测试,并且您的 15 像素图像被放大到 23 像素,导致像素化)。
哈!
Density-independent pixels (i.e.
dip
ordp
in XML) are designed to provide a more consistent visual appearance across devices by scaling the UI to look roughly the same size on each device. This is not the exact same as physical size scaling, but rather the pixel density (dpi) of the screen. There are basically four buckets any device can fall into (ldpi, mdpi, hdpi, xhdpi). Thedp
unit is modeled after mdpi, and all other buckets are scale factors from there. In other words, 15dp does equal 15px on an mdpi device, but not on others.What you need to do for optimum performance is to create your icon in four sizes, and place them in corresponding
drawable/
directories. For instance, with your 15dp icon you should have:The application will grab the proper asset to match the resolution of the device you are running on. If you do not create an asset for each level, the application will take the closest match and scale it up or down (You are probably using an HDPI device to test and your 15px image was getting scaled up to 23px, causing pixelation).
HTH!
根据此页面,dp是与比例无关的单位像素:160dp 在屏幕上始终为 1 英寸。这应该可以回答您的问题,像素是否为 dp:只有支持 160dpi 的屏幕才会出现这种情况。这比当今常见的 PC 屏幕(96 dpi)要高得多。
According to this page, dp is a unit of scale-independent pixels: 160dp always makes 1 inch on your screen. This should answer your question whether pixel is dp or not: It is only the case with a screen supporting 160dpi. This is a lot more than e.g. the usual PC screens these days (96 dpi).