了解绘图和图像大小 [英] Understanding Drawables and Images sizes

查看:59
本文介绍了了解绘图和图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我进行了大量搜索以了解其工作原理,但是我没有找到简单的教程.例如,此视图:

这些是我的drawables文件夹:

所选设备为:Pixel 5.0 1080 x 1920(xxhdpi).

想象一下,以这种分辨率(1080 x 1920),我将图像视图的顶部设置为蓝色(Solutis),其宽度为700px,高度为250px,我该如何为每个drawables文件夹调整图像的大小?

我找到了以下信息:

  LDPI-0.75倍MDPI-原始大小//在这里表示1.0倍HDPI-1.5倍XHDPI-2.0倍XXHDPI-3倍XXXHDPI-4.0倍 

还有

  LDPI:纵向:200 X 320pxMDPI:肖像:320 X 480pxHDPI:肖像:480 X 800pxXHDPI:人像:720 X 1280pxXXHDPI:肖像:960 X 1600pxXXXHDPI:肖像:1440 x 2560px 

在这里,我不明白为什么在设计上选择我的vistuel设备1080 x 1920px时编辑它说xxhdpi和xxhdpi是960 X 1600px ...

对于不同的drawables,图像的不同大小会是什么?

如果有人可以发布项目示例,请给我看看.

解决方案

您是否已检查文档?这是有趣的部分:

与密度无关的像素(dp)

在定义UI布局时应使用的虚拟像素单位,以与密度无关的方式表示布局尺寸或位置.

与密度无关的像素等效于160 dpi屏幕上的一个物理像素,这是系统为中"像素假定的基线密度.密度屏幕.在运行时,系统会根据使用中屏幕的实际密度,根据需要透明地处理dp单位的任何缩放比例.dp单位到屏幕像素的转换很简单:px = dp *(dpi/160).例如,在240 dpi屏幕上,1 dp等于1.5物理像素.在定义应用程序的用户界面时,应始终使用dp单位,以确保在具有不同密度的屏幕上正确显示用户界面.

这意味着,如果您的设备具有更高的密度,则将选择更大的图像.

Firstly I did a lot of search to understand how it work, but I don't find simples tutorials. An exemple, this view:

These are my drawables folders:

The selected device is: Pixel 5.0 1080 x 1920 (xxhdpi).

Immagine in this resolution (1080 x 1920) I set the image view on the top in blue color (Solutis) with 700px of width and 250 px of height, how I have to resize this images for each drawables folders ?

I found this informations:

LDPI - 0.75x
MDPI - Original size // means 1.0x here 
HDPI - 1.5x
XHDPI - 2.0x
XXHDPI - 3x
XXXHDPI - 4.0x

And

LDPI: Portrait: 200 X 320px
MDPI: Portrait: 320 X 480px
HDPI: Portrait: 480 X 800px
XHDPI: Portrait: 720 X 1280px
XXHDPI: Portrait: 960 X 1600px
XXXHDPI: Portrait: 1440 x 2560px

Here I don't understand why when I select my vistuel device 1080 x 1920px on the Design Edit it say xxhdpi and xxhdpi is 960 X 1600px...

And what gonna be the different sizes of the image for the differents drawables ?

If someone can publish a project exemple, I wool look on, please.

解决方案

Did you check the documentation? Here is the interesting part:

Density-independent pixel (dp)

A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way.

The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.

This means if your device as a higher density a bigger image will been chosen.

这篇关于了解绘图和图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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