Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 views
in Technique[技术] by (71.8m points)

android - What has to be used, content_main or Activity_main?

Since after the new update in Android studio, the addition of the XML files has brought some confusion.

While setting the parameters for setContentView(), which XML has to be used? Content_main or Activity_main ?

And if I want to add an Layout file (XML) do I have to create 2 files with the same names?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

While setting the parameters for setContentView, which XML has to be typed ? Content_main or Activity_main ?

You should use content_main.xml to put your views but pass activity_main.xml as the parameter to you setContentView() method.

activity_main.xml is used to display coordinatorLayout, tabLayout, floatingActionButton, viewPager etc.

content_main.xml is used to display your stuff i.e. what you want to display to users.

reference

And if I want to add an Layout file (XML) do I have to create 2 files with the same name ?

Totally depends on the nature of the activity you are creating the layout for. The difference above will help you decide whether you need two or one.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...