Android Studio 视图解析

Android Studio一共有三种视图.我们来分别分析每一种视图的作用.

一.Project视图.(白色字体的目录/文件可不关注)

图片中的链接
Android的Module推荐这么写.gitignore文件
<div class="linenums" style="color: rgb(30, 52, 123); margin-top: 0px; margin-bottom: 0px; padding-left: 0px;"><div class="L0" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">build</span></code></div><div class="L1" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);">*.</span><span class="pln" style="color: rgb(72, 72, 76);">iml</span></code></div></div>
Android的项目.gitignore文件推荐这么写
<div class="linenums" style="color: rgb(30, 52, 123); margin-top: 0px; margin-bottom: 0px; padding-left: 0px;"><div class="L0" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);">#</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Built</span><span class="pln" style="color: rgb(72, 72, 76);"> application files  </span></code></div><div class="L1" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);">*.</span><span class="pln" style="color: rgb(72, 72, 76);">apk  </span></code></div><div class="L2" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);">*.</span><span class="pln" style="color: rgb(72, 72, 76);">ap_  </span></code></div><div class="L3" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L4" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);">#</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Files</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">for</span><span class="pln" style="color: rgb(72, 72, 76);"> the </span><span class="typ" style="color: teal;">Dalvik</span><span class="pln" style="color: rgb(72, 72, 76);"> VM  </span></code></div><div class="L5" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);">*.</span><span class="pln" style="color: rgb(72, 72, 76);">dex  </span></code></div><div class="L6" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L7" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);">#</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Java</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">class</span><span class="pln" style="color: rgb(72, 72, 76);"> files  </span></code></div><div class="L8" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);">*.</span><span class="kwd" style="color: rgb(30, 52, 123);">class</span><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L9" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L0" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);">#</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Generated</span><span class="pln" style="color: rgb(72, 72, 76);"> files  </span></code></div><div class="L1" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">bin</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L2" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">gen</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L3" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L4" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);">#</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Gradle</span><span class="pln" style="color: rgb(72, 72, 76);"> files  </span></code></div><div class="L5" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">gradle</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L6" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">build</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L7" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L8" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);">#</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Local</span><span class="pln" style="color: rgb(72, 72, 76);"> configuration file </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">sdk path</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> etc</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L9" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">local</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">properties  </span></code></div><div class="L0" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L1" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);">#</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Proguard</span><span class="pln" style="color: rgb(72, 72, 76);"> folder generated by </span><span class="typ" style="color: teal;">Eclipse</span><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L2" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">proguard</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L3" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L4" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);">#</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Log</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Files</span><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L5" style="color: rgb(190, 190, 197); line-height: 18px; padding-left: 0px; list-style-type: none;"><code class="language-java" style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);">*.</span><span class="pln" style="color: rgb(72, 72, 76);">log </span></code></div></div>
 

二.Packages视图

该视图下和Project最大的区别就是隐藏了中的配置文件,属性文件和系统自身的目录.
只是显示了当前的Module列表和Module下面的目录,文件.
 

三.Android视图

Andrid视图是新版的AS新推出来的一个视图.很多人都是从Ecplise的开发中转过来的,习惯了Project视图.
使用了一下Android视图.发觉确实有它的去多优点.
由于大部分的目录,文件都在第一个个视图中详细进行的标注.这里就不在一一标注了.
可以看到在Android视图下的一级目录分两个区域,一个是Module列表区域,一个是Gradle脚本区域
 
Module目录下分三个子目录,分别对应mainfests文件,java源码,res资源目录.
图中,有多个目录和文件名是相同的.但是后面带有一个标识.例如diesns.xml文件有两个,一个后面带有(w820dp)
意思说手机的可用宽度至少要820dp的情况下才会引用该文件下的dimens值.具体请参考链接:
我们比较关心这样的文件是怎么建立的.其实前面已经说了,Project的所有视图都是真实的目录.而在
Android视图下,很大目录都是不存在,是由Android视图自动合并在了一起,方便我们理解和布置.
eg:
切换到Project视图中,就是在该目录下的一个dimens文件
Android视图自动把它们合并到一起,表示这几个文件的作用是一样的,只不过会因为设备的不同,而引用不同目录下的文件.
 
 
Gradle脚本目录下有多个Gradle文件和属性文件.
看其后面的提示,从上到下分别为:项目空间的gradle配置文件,第一个module和第二个module配置文件.
gralde属性文件,设置文件,以及本地SDK路径属性文件.
这些文件在Project中已经详细的说明了.这里就不一一解释.
 
Adnroid视图最大的好处就是去掉一些我们本身不关心的文件和目录.(配置,属性文件等)并且把一些资源文件,源文件很清晰的合并在一起.
隐藏了一些自动自动生成的文件和目录(例如R文件等)可以让我们更方法的管理整个项目/module.
原文地址:https://www.cnblogs.com/chenliyang/p/6559308.html