简体   繁体   English

如何正确使用DPI分辨率

[英]How to proper use DPI resolutions

I know I need to use different DPI for images and all graphics stuff, but I just don't understand if I have to create the different drawable folders by myself or if there's a proper way to do it , and plus, what to use them for . 我知道我需要对图像和所有图形使用不同的DPI ,但我只是不知道是否必须自己创建其他可绘制文件夹,或者是否有适当的方法来使用它 ,以及使用它们的方法为

For instance I need to add a wallpaper , where should I put it? 例如,我需要添加墙纸 ,应该放在哪里? And of what resolutions? 以及哪些决议? What are the pixels needed for each? 每个像素需要多少像素?

Tried to read the Google page about this, but didn't get much, thank you! 试图阅读有关此内容的Google页面,但了解不多,谢谢!

I have to create the different drawable folders by myself or if there's a proper way to do it? 我必须自己创建其他可绘制文件夹,或者是否有适当的方法来创建它?

Assuming you're using Android Studio: 假设您使用的是Android Studio:

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

what to use them for. 用它们做什么。

from http://developer.android.com/guide/practices/screens_support.html : 来自http://developer.android.com/guide/practices/screens_support.html

  • xlarge screens are at least 960dp x 720dp xlarge屏幕至少为960dp x 720dp
  • large screens are at least 640dp x 480dp 大屏幕至少为640dp x 480dp
  • normal screens are at least 470dp x 320dp 普通屏幕至少为470dp x 320dp
  • small screens are at least 426dp x 320dp 小萤幕至少为426dp x 320dp

In that page you have documentation for screen sizes and densities. 在该页面中,您可以找到有关屏幕尺寸和密度的文档。 Basically, when you put, let's say, an image in an activity, it will render according to the device's density corresponding folder. 基本上,假设您将某张图片放入活动中,它将根据设备的密度渲染相应的文件夹。

a wallpaper, where should I put it? 墙纸,我应该放在哪里?

The best is to have an image for each density, but if you don't have those provided, you can put it in the drawable folder, without any density qualifier, which means that your resource is the same for every screen density. 最好是为每个密度都有一个图像,但是如果没有提供这些图像,则可以将其放在可绘制的文件夹中,而无需任何密度限定符,这意味着您的资源对于每个屏幕密度都是相同的。

For a quick way of knowing your device screen stats, download ScreenInfo. 要快速了解设备屏幕状态,请下载ScreenInfo。

"...I just don't understand if I have to create the different drawable folders by myself" “ ...我只是不明白是否必须自己创建其他可绘制文件夹”

  • no , you don't have to, but you can. ,您不必这样做,但是可以。

"... if there's a proper way to do it" “ ...如果有适当的方法可以做到这一点”

  • If you right click on res then select new then select Image Asset , Android Studio has an Image Asset tool that guides you through the whole process. 如果右键单击res然后选择new然后选择Image Asset ,Android Studio会提供Image Asset工具来指导您完成整个过程。 This is how you import various UI elements in their correct dpi and densities. 这是您以正确的dpi和密度导入各种UI元素的方式。

"... what to use them for" “ ...将它们用于什么”

  • This is upto you. 这取决于你。 But if you set an ImageButton to an drawable with various drawable resources for different screen dpi, the correct dpi drawable will be chosen according to the device's screen dpi when the app is running. 但是,如果将ImageButton设置为具有针对不同屏幕dpi的各种可绘制资源的drawable绘制对象,则在应用程序运行时,将根据设备的屏幕dpi选择正确的dpi可绘制对象。

"wallpaper..?" “墙纸..?”

  • Put that in drawable-nodpi or just the regular drawable 将其放入drawable-nodpi或仅将常规drawable

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM