java android中不同屏幕尺寸的可绘制尺寸
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17261344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
drawable sizes for different screen sizes in android
提问by Fcoder
i have a problem in android development that bored me. my problem is screen size and dealing with that. specially i have some problems with images. for example i want to create a background image for my activity that i created in photoshop and my background image contains a "HELLO" word on it. but when i put it on drawable-xhdpi folder, it seems blurry and its not sharp!! my phone is a nexus 4 and according to Google documentation i create background image in 640 x 480 size.
我在 android 开发中遇到了一个让我感到无聊的问题。我的问题是屏幕尺寸和处理。特别是我有一些图像问题。例如,我想为我在 photoshop 中创建的活动创建一个背景图像,并且我的背景图像上包含一个“HELLO”字样。但是当我把它放在 drawable-xhdpi 文件夹时,它看起来很模糊而且不清晰!!我的手机是 nexus 4,根据 Google 文档,我创建了 640 x 480 大小的背景图像。
when i create background image in 960 x 720 size it seems better but not perfect. in this case my image file size is very high!
当我创建 960 x 720 大小的背景图像时,它看起来更好但并不完美。在这种情况下,我的图像文件大小非常大!
but what is the standard way for this? please help me to solve this problem for ever. i read google documentation but its not solve my problem! http://developer.android.com/guide/practices/screens_support.html
但这样做的标准方法是什么?请帮我永远解决这个问题。我阅读了谷歌文档,但它没有解决我的问题! http://developer.android.com/guide/practices/screens_support.html
采纳答案by MaciejGórski
You should usually avoid creating images for certain screen sizes to make them background, because there are thousands of different devices and you would have to create dozens of such images.
您通常应该避免为某些屏幕尺寸创建图像以使其成为背景,因为有成千上万种不同的设备,您将不得不创建许多这样的图像。
The first thing you need to be aware of is screen density.
您需要注意的第一件事是屏幕密度。
Generally you create 3 to 5 images when not even looking at screen size: low (120 dpi), medium (160 dpi), high (240 dpi), extra high (320 dpi) and 2*extra high (480 dpi). These go into drawable-Xdpi folders, where X is one of l, m, h, xh, xxh.
通常,即使不查看屏幕尺寸,也会创建 3 到 5 张图像:低 (120 dpi)、中 (160 dpi)、高 (240 dpi)、超高 (320 dpi) 和 2* 超高 (480 dpi)。它们进入 drawable-Xdpi 文件夹,其中 X 是 l、m、h、xh、xxh 之一。
Next thing when you want to have bigger images on bigger screens (bigger phones, small and big tablets), you may want to put images to folders like drawable-sw600dp-Xdpi. This is not a case for your phone.
接下来,当您想在更大的屏幕(更大的手机、小型和大型平板电脑)上拥有更大的图像时,您可能希望将图像放入像 drawable-sw600dp-Xdpi 这样的文件夹中。这不是您手机的情况。
Nexus 4is a xhdpi 640x384 dp device, but you should not treat it differently than Samsung Galaxy S2 (hdpi 533x320 dp).
Nexus 4是 xhdpi 640x384 dp 设备,但您不应将其与三星 Galaxy S2(hdpi 533x320 dp)区别对待。
Create an image of smaller size for both phones and center it horizontally. E.g. 320x100 px for mdpi, 480x150 px for hdpi and 640x200 px for xhdpi (your phone).
为两部手机创建一个较小尺寸的图像并将其水平居中。例如,mdpi 为 320x100 像素,hdpi 为 480x150 像素,xhdpi(您的手机)为 640x200 像素。
回答by Quamber Ali
With 1600+ android models even after they are categorized in few Screen size and a few DPI's its very difficult to manage layouts.. i suggest that you just concentrate on designing layouts w.r.t to screen sizeand then create views as Resizeable Viewsto neglect density effects.
随着他们在几个屏幕尺寸分类和几个DPI的它非常难以管理布局即使1600+的Android机型..我建议你只是专注于设计布局WRT屏幕大小,然后创建意见,可调整大小的意见忽视密度效应.
Once you have created your layouts Resize the Views .. You can create a Custom View or resize on its onMeasure();
创建布局后,调整视图的大小.. 您可以创建自定义视图或在其 onMeasure() 上调整大小;
回答by Krzysiek
This is problem of Android Fragmentation and you just cannot deal with it perfectly as there is a several hundreds different devices. As colleague above wrote Nexus 4 has resolution -1280 x 768 so for sure res of image as equal as 960 x 720 is good choice. I'm even surprised that google suggest 640 x 480 for xhdpi, it's definitely too less.
这是 Android Fragmentation 的问题,您无法完美地处理它,因为有数百种不同的设备。正如上面的同事所写,Nexus 4 的分辨率为 -1280 x 768,因此可以肯定图像的分辨率等于 960 x 720 是不错的选择。我什至很惊讶谷歌为 xhdpi 建议 640 x 480,这绝对太少了。
So as I said you are not able to make perfect looking graphics for all existing devices. You should choose the most popular devices from every screen category(xhdpi,mdpi,ldpi ... etc) to cover the most important market share.
因此,正如我所说,您无法为所有现有设备制作外观完美的图形。您应该从每个屏幕类别(xhdpi、mdpi、ldpi 等)中选择最流行的设备,以覆盖最重要的市场份额。
回答by MineScript
the screen resolution for Nexus is 1280x768 (http://www.google.com/nexus/4/specs/), resize the image to this resolution. In especial consideration some images can't handle the resolution and the image became disproportionately.
Nexus 的屏幕分辨率为 1280x768 ( http://www.google.com/nexus/4/specs/),将图像调整为该分辨率。特别是一些图像无法处理分辨率,图像变得不成比例。
for interesting resolution calculator: http://members.ping.de/~sven/dpi.html
有趣的分辨率计算器:http: //members.ping.de/~sven/dpi.html