Files activity_main.xml and content_main.xml

1

I read the answer they gave to: "What is the difference between content_main xml and activity_main xml in Android studio ?" from 6 months ago.

I clear the doubt. But another one comes up: In which of the two should I place the objects ( TextView , Button , etc.) of the design part? Because both files .xml have a design part (Design).

I have Android Studio 2.2.3 installed. Thank you very much.

    
asked by Ace_331 04.07.2017 в 06:50
source

1 answer

1
  

"What is the difference between content_main xml and activity_main xml in   Android studio? "

The difference is actually just the name, and that content_main.xml, is usually used to load other elements using an include, by:

include layout="@layout/content_main

But it is simply a nomenclature which is not a restriction.

Both files can contain the elements you want to show in your UI and can be called as you wish. (keeping the restriction for resource naming), you can even create your own layout.

For example layout_principal.xml , add elements and load it with setContentView() to your Activity and create another layout containing elements of the UI called contenido_principal.xml , which would be loaded by <include> .

  

In which of the two do I place the objects (TextView, Button, etc.)   of the design part? Because both .xml files have a design part   (Design)

You can place it directly inside the layout that loads your Activity by setContentView() or if you want you can add them in another layout that would be for example content_main.xml , and load this layout from the main layout by:

include layout="@layout/content_main

I recommend you read:

Reusing layouts with <include>

    
answered by 04.07.2017 в 09:56