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?

- 13,183
- 12
- 43
- 79

- 1,141
- 2
- 11
- 11
-
1can you post the link to the tutorial? – pgiitu Oct 17 '15 at 05:30
-
https://www.youtube.com/watch?v=9l1lfWAiHPg – Chris Daniel Oct 17 '15 at 05:32
-
You should be using `activity_main.xml`. check my answer – pgiitu Oct 17 '15 at 05:35
-
content_main.xml is used for the fab and activity_main.xml is for other part of the activity. – aravindkanna Jun 22 '16 at 11:34
6 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:
activity_main.xml
this xml file is used to display coordinatorLayout
, tabLayout
, floatingActionButton
, viewPager
etc..
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....

- 6,849
- 8
- 37
- 59

- 984
- 6
- 15
-
10Just to elaborate - and see @SherlockSun's answer - he's the only one who explicitly points out that activity_main.xml contains an "include" for content_mail.xml. These two layout files are related, they describe different aspects of the overall layout. – RenniePet Aug 28 '16 at 00:20
-
That's right...But for those who are new to the android environment explaining things this way is much better...and the question was about which XML to use. – Chordin4tion Aug 30 '16 at 07:30
-
@Chordin4tion - What if I dont want to use coordinatorLayout, tabLayout, floatingActionButton or viewPager and want a simple layout? Do I still use content_main.xml and leave activity_main.xml unused? – Shubs Dec 04 '17 at 08:44
-
2@Shubs That's totally up to you...If you don't want to use two different layout you can use `activity_main.xml` and remove the include tag from `activity_main.xml`. You can remove coordinator layout, tab layout and other stuff and replace parent layout with whatever layout you are planning to use. – Chordin4tion Dec 05 '17 at 10:30
-
1"stuff i.e. what you want to display to users" –Floating action button is not something you want to display to users? – Julius Feb 15 '19 at 10:41
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
.

- 13,183
- 12
- 43
- 79

- 151
- 1
- 3
Android Studio 1.4 gives a default new option of content_main.xml
in the activity. actually activity load the xml file of activity_main.xml
for your layout. content_main.xml
is the part of main.xml
.
you can use both for layout,but main.xml
is necessary for your Activity. its a option to choose the content_main.xml
for design of layout.
Hope you get it.

- 13,183
- 12
- 43
- 79

- 2,112
- 2
- 13
- 18
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).
content_main.xml
file will be generated when you choose "blank activity". This activity will be having floating button by default at the bottom of the screen.
But when you choose "empty activity" then content_main.xml
won't be generated and it won't be having floating button, but just simple Activity.

- 13,183
- 12
- 43
- 79

- 1,046
- 9
- 12
activity_main and content_main are linked to each other.
You can use either both. But to be specific, you should use activity_main.
let me explain this further.
activity_main, this is where the content_main is placed. This is a mother and child case, where activity_main is the mother and content_main is the child.
content_main, this is where you put your controls / content e.g button. This represents as the body of your design.

- 386
- 2
- 21
These are just 2 xml layout files which basically represent 2 different layouts. You should use the file based on the layout you want to use in your android app.
Based on the tutorial it is simple that you should use activity_main.xml
as it is the layout for the MainActivity
.
You can also see the preview of the layout file in android studio as to how it will look in the app.

- 1,671
- 1
- 15
- 23
-
1
-
-
2This is not correct - they are not two different layouts. See @SherlockSun's answer - he's the only one who explicitly points out that activity_main.xml contains an "include" for content_mail.xml. So the two layout files are related, they describe different aspects of the overall layout. – RenniePet Aug 28 '16 at 00:12
-
Let's put it in another way, when you embed some html code to the html code, it does not mean that those html's are different pages. There is only one page but consisted of two pieces... – Nusrat Nuriyev Mar 21 '21 at 12:47