为什么不能使用大写字母在Android的命名资源? [英] Why is it not possible to use uppercase in naming resources in android?

查看:754
本文介绍了为什么不能使用大写字母在Android的命名资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我开始在开发Android的应用程序和大量的教程都表示,我们不应该在命名资源使用大写。这是为什么?也不允许给扩展如巴纽和.xml。如果我有两个文件button.png和button.xml如何应用这两个文件之间区别?


解决方案

  1. 不要让大写字母的资源仅仅是遵循一些约定严格


  2. 在不能在相同的资源文件夹使用两种不同类型相同名称的资源。例如说,你在绘制-HPDI两个资源文件。他们是a.png和a.xml。在这里,在编译,编译器会显示错误。
    但是,如果你把在绘制,绘制MDPI,华电国际和a.xml a.png,那么就不会显示任何错误因为这两个资源将两种完全不同类型的设备中使用。


我发现,如果你在同一文件夹中使用a.png和a.xml然后错误将显示a.xml另一个有趣的事情是重复的。但是,如果你在同一文件夹中使用A.JPG和a.png然后将显示该a.png是重复的。为此,我们可以猜测,没有任何文件类型的优先级。编译器遵循自上而下的搜索。作为a.png放置在a.xml所以compliler会先找到a.png然后当他们发现他们会表现出错误同名的XML文件。和用于在使用A.JPG和a.png同样的原因,a.png将显示错误

N.B。这个答案是完全根据我的观察。我没有找到关于此的任何书面文件。所以,如果有人证明我错了举证那么这将是pciated高度AP $ P $

I recently started developing applications in android and a lot of tutorials have said that we shouldn't use uppercase in naming the resources. Why is that? Also it is not allowed to give extensions such as .png and .xml. If i have two files button.png and button.xml how does the app differentiate between the two files?

解决方案

  1. not to allow uppercase letter in resources is just to follow some convention strictly

  2. you can not use two different types of resources of a same name in the same resource folder. for example say you have two resource files in drawable-hpdi. they are a.png and a.xml. Here while compiling the compiler will show error. But if you place a.png in drawable-hdpi and a.xml in drawable-mdpi, then it will not show any error as these two resources will be used in two totally different device types.

Another interesting thing I found that if you use a.png and a.xml in same folder then the error will show that a.xml is duplicate. But if you use a.jpg and a.png in same folder then it will show that the a.png is duplicate. For that we can guess that there is no file type priority. The compiler follow a top down search. as a.png is placed over a.xml so the compliler will first find a.png then when they find xml file of same name they will show error. and for the same reason while using a.jpg and a.png, a.png will show error.

N.B. This answer is totally based on my observation. I didnt find any written documentation on this. So if anybody proves my wrong with proof then that will be highly appreciated

这篇关于为什么不能使用大写字母在Android的命名资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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