Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between content_main.xml and activity_main.xml?

Tags:

android

xml

I am new to 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 have been following Bucky's tutorial and he just has the activity_main.xml. Which one should I use?

like image 685
Chris Daniel Avatar asked Oct 17 '15 05:10

Chris Daniel


People also ask

What is the difference between Content_main xml and Activity_main xml?

The activity_main. xml is the "outer" part of the activity layout (toolbar, action button, etc.) and content_main. xml is the inner part where you put your own layout (the blank space).

What is Activity_main xml?

The activity_main.xml is a layout file available in res/layout directory, that is referenced by your application when building its interface. You will modify this file very frequently to change the layout of your application.

Why do we use Activity_main xml?

According to new design pattern in android studio activity_main. xml will determine how the look of the main activity should be. And on the other hand content_main. xml will determine the contents in the activity_main.

What is the difference between activity and layout?

Layout is where you organize the views in your page. But without activity, they have no meaning. Because in activity, you have to get these views and use them programmaticaly. All together, you load views from layout to activity and in activies you implement your whole program.


2 Answers

Unlike previous version, the new API 23 comes with the coordinatorLayout and stuff and just to make them simple to use android has distinguished activity's layout into two different layout i.e. content_main.xml & activity_main.xml.

I'll explain what they are for:

  1. activity_main.xml

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

  1. content_main.xml

This xml file is use to display your stuff i.e. what you want to display to users.

So, if you are just asking in which xml you have to put your stuff, content_main.xml is the one....

like image 133
Chordin4tion Avatar answered Oct 03 '22 03:10

Chordin4tion


I think the content_main.xml is a part of activity_main.xml. Because there is include layout="@layout/content_main" in the activity_main.xml.

like image 36
SherlockSun Avatar answered Oct 03 '22 02:10

SherlockSun