简体   繁体   English

在Android应用程序设计中使用特定于大小和密度的资源问题

[英]Use size and density-specific resources problems in Android app design

Today, I read the android tutorial about supporting multiple screen. 今天,我阅读了有关支持多屏幕的android教程。 I got some problems here. 我在这里遇到了一些问题。 In the tutorial, it says we can use size and density-specific resource in this way: 在本教程中,它说我们可以通过以下方式使用特定于大小和密度的资源:

res/layout-w600dp/main_activity.xml RES /布局w600dp / main_activity.xml

I know that w600dp means the available width is 600dp. 我知道w600dp表示可用宽度为600dp。 But is it for portal or landscape? 但这是门户还是景观?

Here is real case: I want to design a full width header image for my android app in portal mode. 这是真实的情况:我想在门户网站模式下为我的android应用程序设计全宽标题图片。 This app is targeted for Samsung Galaxy S4, which has 5.0 inches, 1080x1920 pixels with 441 dpi. 这个应用程式的目标对象是拥有5.0吋,1080x1920像素和441 dpi的Samsung Galaxy S4。 That means my header image need to be 1080 pixels. 这意味着我的标题图片必须为1080像素。 As android tutorial mentioned, in android, px = dp * (dpi/160); 如android教程所述,在android中,px = dp *(dpi / 160); In Samsung Galaxy S4 example, 1080px width is 391dp. 在Samsung Galaxy S4示例中,1080px宽度为391dp。 So do I need to declare the layout in : 所以我需要在以下位置声明布局

res/layout-w391dp/main_activity.xml RES /布局w391dp / main_activity.xml

or 要么

res/layout-w320dp/main_activity.xml RES /布局w320dp / main_activity.xml

When I am using Photoshop to create my header image, do I need to set my image parameter as 1080 width, 40 height and 441dpi ? 当我使用Photoshop创建标题图像时, 是否需要将图像参数设置为1080宽度,40高度和441dpi After I get the image, do I need to put this image in : 获取图像后, 是否需要将该图像放入

res/drawable-xhdpi/ RES /抽拉-xhdpi /

or 要么

res/drawable-w600dp/ RES /抽拉-w600dp /

The available width value will change when the orientation changes between landscape and portrait to match the current actual width. 当方向在横向和纵向之间变化以匹配当前实际宽度时,可用宽度值将更改。

If you want provide different layouts/resources for landscape and portrait add the qualifier name -land or -port respectively. 如果要为横向和纵向提供不同的布局/资源,请分别添加限定符名称-land-port See more at Android documentation Android文档中查看更多信息

If you want fill all the available width don't think about dpi. 如果要填充所有可用宽度,请不要考虑dpi。 If device width is 1080px then you need an image with 1080px. 如果设备宽度为1080px,则需要具有1080px的图像。 However, if you want an image look the same at diferent devices with diferent density then calculate its dimensions by applying these factors: 但是,如果您希望图像在不同密度的不同设备上看起来相同,则可以通过应用以下因素来计算其尺寸:

ldpi = 0.75 ldpi = 0.75
mdpi = 1 mdpi = 1
hdpi = 1.5 hdpi = 1.5
xhdpi = 2 xhdpi = 2
xxhdpi = 3 xxhdpi = 3

It is not possible here to do a full explanation on this subject, and my English is not enough for such. 这里不可能对这个主题做完整的解释,而我的英语还不够。

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

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