Difference between content_main.xml and activity_main.xml?

前端 未结 6 1357
盖世英雄少女心
盖世英雄少女心 2020-11-28 08:16

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).

相关标签:
6条回答
  • 2020-11-28 08:52

    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.

    0 讨论(0)
  • 2020-11-28 08:53

    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.

    0 讨论(0)
  • 2020-11-28 08:55

    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.

    0 讨论(0)
  • 2020-11-28 08:56

    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....

    0 讨论(0)
  • 2020-11-28 09:02

    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.

    0 讨论(0)
  • 2020-11-28 09:13

    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.

    0 讨论(0)
提交回复
热议问题