android中的不同值文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21280277/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:16:52  来源:igfitidea点击:

Different values folders in android

androidresourcesdimensions

提问by John R

I am creating different valuesfolders in my app (values, values-ldpi, values-mdpi, values-hdpi, values-xhdpi, values-nodpi, values-w360dp-mdpi). But some devices that belong same category. But having different screen sizes. But I see give font size according to device densitiesin this the answer provided by @PankajSharma suggest to create folders like-

我正在values我的应用程序中创建不同的文件夹(values, values-ldpi, values-mdpi, values-hdpi, values-xhdpi, values-nodpi, values-w360dp-mdpi)。但是一些属于同一类别的设备。但是有不同的屏幕尺寸。但是我看到根据设备密度给出字体大小@PankajSharma 提供的答案建议创建文件夹,例如-

res/values/dimens.xml    
res/values-small/dimens.xml    
res/values-normal/dimens.xml    
res/values-xlarge/dimens.xml

I want to know what is the difference b/w my way and the other way? I think the answer provided by @PankajSharma is easy. I also want to know which way is better?

我想知道我的方式和其他方式的黑白有什么区别?我认为@PankajSharma 提供的答案很简单。我也想知道哪种方式更好?

回答by Rakeeb Rajbhandari

The approach you are using is a valid approach, but a little outdated. From HoneyComb, there is a new wayto fix all of this. Your resources folder should now look like this:

您使用的方法是一种有效的方法,但有点过时。从HoneyComb,有一种新方法可以解决所有这些问题。您的资源文件夹现在应如下所示:

enter image description here

在此处输入图片说明

Please refer to the link I have posted and familiarize yourself with Smallest Widthconcept.

请参阅我发布的链接并熟悉Smallest Width概念。

Hope this helps :)

希望这可以帮助 :)

EDIT: Adding to this post, try to establish some kind of standardization in your dimens.xml, something like this:

编辑:添加到这篇文章中,尝试在您的 中建立某种标准化dimens.xml,如下所示:

enter image description here

在此处输入图片说明

Doing this makes it easier to maintain code, plus it reduces the number of dimenfolders. Normally rather than having values-hdpi, values-xhdpi, etc. files like values-sw480dp-xhdpimight have more values to adjust, but then again all of this is contextual.

这样做可以更轻松地维护代码,此外还减少了dimen文件夹的数量。通常,而不是具有values-hdpi,values-xhdpi等文件,例如values-sw480dp-xhdpi可能有更多的值需要调整,但所有这些都是上下文。

回答by Rahul Gupta

Create a Single layout for default screens 4.7 inch (hdpi) in layout folder and dimensions in values folder. This is your Superset.

在布局文件夹中为默认屏幕 4.7 英寸 (hdpi) 和值文件夹中的尺寸创建单一布局。这是你的Superset

Now let say you want your layouts for 7inch devices. Create values-sw600dp folder for 7inch in Portrait orientation

现在假设您想要 7 英寸设备的布局。以纵向为 7 英寸创建 values-sw600dp 文件夹

Now lets say you want your layouts for 10 inch devices Create values-dw720dp folder

现在假设您想要 10 英寸设备的布局 创建 values-dw720dp 文件夹

NOTE :- For landscape just add "-land" in front of folder names.

注意:- 对于横向,只需在文件夹名称前添加“-land”。

Now lets say you have new devices such as Xperia SP (4.7' and XHDPI) and Nexus 5(5" and XXHDPI).

现在假设您有新设备,例如 Xperia SP(4.7' 和 XHDPI)和 Nexus 5(5" 和 XXHDPI)。

For these, you can create values-xhdpi and values-xxhdpi folders and similary add -land for landscape orientation..

对于这些,您可以创建 values-xhdpi 和 values-xxhdpi 文件夹,并为横向添加类似的 -land ..

I hope you got the point of how to create folders..

我希望你明白如何创建文件夹。

Now your superset is defined in values folder. Most of the dimensions will be used from here only. Now run your app in other devices. Whatever mismatch is occuring just add that specific dimension in their respective values folder

现在您的超集在 values 文件夹中定义。大多数维度将仅从这里使用。现在在其他设备上运行您的应用程序。无论发生什么不匹配,只需在各自的值文件夹中添加该特定维度

To check from which folder your layouts, images are used, use my trick.

要检查您的布局、图像是从哪个文件夹中使用的,请使用我的技巧。

Create five same strings and put in it all the values folders like this :- Default Screen Screen 4.7 XHDPI Screen MDPI Screen

创建五个相同的字符串并将所有值文件夹放入其中,如下所示:- Default Screen Screen 4.7 XHDPI Screen MDPI Screen

Create five drawable folders, most of them will be already there : - drawable-hdpi, drawable-mdpi, drawable-xhdpi, drawable-xxhdpi, drawable-xxxhdpi Put the screenshots below in their respective folder under the same name

创建五个drawable文件夹,其中大部分已经存在:- drawable-hdpi, drawable-mdpi, drawable-xhdpi, drawable-xxhdpi, drawable-xxxhdpi 将下面的截图放在各自文件夹下的同名文件夹下

enter image description hereenter image description hereenter image description hereenter image description hereenter image description here

在此处输入图片说明在此处输入图片说明在此处输入图片说明在此处输入图片说明在此处输入图片说明

This is how my res folder looks like and i am supporting all the devices from 4.7 screen and above :-

这就是我的 res 文件夹的样子,我支持 4.7 屏幕及以上的所有设备:-

enter image description here

在此处输入图片说明