Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I updated my android studio to latest version that is android studio1.4.

By default in a new project, there is a file content_main.xml in layout folder.
What is the use of this file?

like image 913
Ritesh Mathur Avatar asked Oct 01 '15 06:10

Ritesh Mathur


People also ask

What is Content_main xml?

content_main. xml is the part of main. xml . you can use both for layout,but main. xml is necessary for your Activity.

What is the role of xml in Android?

XML tags define the data and used to store and organize data. It's easily scalable and simple to develop. In Android, the XML is used to implement UI-related data, and it's a lightweight markup language that doesn't make layout heavy. XML only contains tags, while implementing they need to be just invoked.

Why xml is used in Android Studio?

Android applications use XML to create layout files. Unlike HTML, XML is case-sensitive, requires each tag be closed, and preserves whitespace. View: An object from Android's built-in View class. It represents a rectangular area of the screen.

What is the role of xml in app design?

Declaring your UI in XML allows you to separate the presentation of your app from the code that controls its behavior. Using XML files also makes it easy to provide different layouts for different screen sizes and orientations (discussed further in Supporting Different Screen Sizes).


2 Answers

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

That is content_main.xml will contain the textview, edittext, button etc component. And it will be included by the activity_main.xml.

So we can think of content_main.xml just like partial in HTML. activity_main.xml will contain your activity global design, and content_main.xml will contain the contents.

From view of what they contain:

activity_main : Co-ordinator layout, ViewPager etc

content_main : Developer choosen elements. textview, edittext, button etc.

What the android developer website says about them is

activity_main:

This XML layout file is for the activity you added when you created the project with Android Studio. Following the New Project workflow, Android Studio presents this file with both a text view and a preview of the screen UI. The file contains some default interface elements from the material design library, including the app bar and a floating action button. It also includes a separate layout file with the main content

content_main:

This XML layout file resides in activity_my.xml (activity_main) , and contains some settings and Textview(other) element.

like image 189
Zahan Safallwa Avatar answered Oct 12 '22 23:10

Zahan Safallwa


The difference between content_main.xml and activity_main.xml (for the class MainActivity) exists since the API 23. The difference between them is the following:

  1. The content_main.xml is used for displaying the things that the user should see. So it contains the elements which are for the user. As you can see in the name, the content_main.xml determines the contents you can find in your Activity (MainActivity in this case). You use this xml-file to add new contents (Views) to your Activity.

  2. The activity_main.xml has some special tasks. It contains for example:

    The floatingActionButton (the small round button you use in gmail for example)

    The tabLayout

    The coordinatorLayout

    So the activity_main.xml determines how the Activity (MainActivity in this case) should look. It determines its design.The content_main.xml is a part of the activity_main.xml.
like image 30
Setu Kumar Basak Avatar answered Oct 12 '22 23:10

Setu Kumar Basak