Zixing Wang
Zixing Wang

Reputation: 131

Why Android Studio creates two xml layout files

The eClipse only creates one acitivity_main.xml file, but Android studio creates two xml layout files. The default layout for acitivity_main.xml is the CoordinatorLayout but for content_main.xml is RelativeLayout.

Why need two xmls ? The default is to refer activity_main as: setContentView(R.layout.activity_main), but I find setContentView(R.layout.content_main) also works.

What is the relationship between these two layouts ?

Is there any difference If I drop a button view to the content_main.xml or I drop a button view to activity_main.xml ?

Thanks

Upvotes: 2

Views: 1425

Answers (1)

Amarjit
Amarjit

Reputation: 4357

Why create 2 files :

These 2 files are created to make your work EASIER. As main file contain your stuff like FAB, toolbar in Coordinate layout. Now your content file is file in which you can make UI of view without interrupting the basic flow. I personally recommend this.

Why need two xmls ? The default is to refer activity_main as: setContentView(R.layout.activity_main), but I find setContentView(R.layout.content_main) also works.

These will work as after all these are layout files so can set as content view.

Is there any difference If I drop a button view to the content_main.xml or I drop a button view to activity_main.xml ?

No difference at all.

Upvotes: 1

Related Questions