4

To my understanding, the content file is just the xml files contents...but in a separate file. Whats the point?

I've seen

What is the role of content_main.xml in android studio 1.4?

and there doesn't seem to be much documentation about content_XXX.xml, so I was wondering, why did the new update include the default creation of this file?

Why divide the code into two files, why not just put all of the contents in its own xml file, I've tried it...and it works. I fail to understand why the content_main file is generated on creation of a new project.

Can someone give me a list of benefits of why I should be using the content file?

Thanks,

Ruchir

Community
  • 1
  • 1
Ruchir Baronia
  • 7,406
  • 5
  • 48
  • 83

1 Answers1

2

activity_main.xml is used to display coordinatorLayout, tabLayout, floatingActionButton, viewPager etc.

content_main.xml is used to display your stuff i.e. what you want to display to users.

for more details check my answer here.

Update after conversation in comments below: The point of doing this is to bring in more organization in the code. We can always go forward with the old way of putting everything in one file. Android Studio is just giving us a start with keeping the layouts in a more organized way to allow easy comprehension of code and reuse wherever possible, by segregating related stuff.

Community
  • 1
  • 1
Viral Patel
  • 32,418
  • 18
  • 82
  • 110
  • But what is the point of all of that? Can't juts keep all of my stuff in `activity_main.xml`? – Ruchir Baronia Jan 10 '16 at 06:42
  • it is more organized. you could also just keep the entire app's content in one xml and show and hide stuff as you need them and reposition them. Technically it is possible, but do we do that? no, because it is not convenient and organized. Seperating things out into separate files as much as we can will bring in more organizing and allow reuse also to certain extent. – Viral Patel Jan 10 '16 at 06:44
  • so android studio is just giving us a start with proper organizing. We can always remove one file and put everything in one way if we want. – Viral Patel Jan 10 '16 at 06:45
  • Ok, I understand it is about organization...but why break up one screen into two xml files? I understand why we would create different screen xml files, but this doesn't make logical sense to me... – Ruchir Baronia Jan 10 '16 at 06:50
  • to allow reuse. You may want to inflate a different set of content in the same activity but changes in ` tabLayout, floatingActionButton, viewPager` are rare. – Viral Patel Jan 10 '16 at 06:53