为什么默认情况下存在content_main.xml和activity_main.xml而不是仅activity_main.xml?
我刚刚开始学习Android App开发.我有Android Studio 1.4.在我的布局文件夹中,我有两个XML文件( content_main.xml
和 activity_main.xml
).我使用在线教程来学习,但是其中只有 activity_main.xml
.因此,我想知道的是在这些相应文件中应使用的功能是什么.我可以只使用 activity_main.xml
并让另一个成为我吗?反之亦然.
I have just begun learning Android App development. I have Android Studio 1.4. In my layout folder I have two XML files (content_main.xml
and activity_main.xml
). I use online tutorials to learn but they have only activity_main.xml
in them. So what i want to know is what are the functions that should be used in these respective files. can i just use activity_main.xml
and just let the other be ? and vice versa.
现代的Android方法基于 Fragments
,它们在某种意义上是小型活动",您可以将其放入活动
,获得了很大的灵活性.
The modern Android approach is based on Fragments
, which are, in a way, "small Activities", which you can put in Activities
, gaining lots of flexibility.
因此, activity_main.xml
只是包含容器的Activity布局(很可能是 FrameLayout
),而 content_main.xml
是在 MainActivity.java
中某个位置放入此容器的片段.您应该研究其中的代码以更好地理解它:)
Therefore, activity_main.xml
is simply the Activity layout containing a container (FrameLayout
most probably) and content_main.xml
is the layout for a Fragment put into this container somewhere within MainActivity.java
. You should study the code in there to understand it better :)