New Android Studio Activity Design Pattern content

I started learning Android, but in new Android Studio 1.4 using blank activity creates two xml files - activity_main and content_main - from what I read this is the new design pattern, but no relatively new tutorial (<1yr) mentions this and operates with blank activity creating only activity_main.

Is there any way around it? Is it possible to create your own activity template or just create activity_main without content_main?

Learning Android for beginner is already enough of a hassle without manually creating java and xml from empty activity every time or trying to "translate" files from tutorials into new design pattern while trying to learn.


There IS a way around it. When you create a new project, on the "Add an activity page", instead of "Blank Activity", choose "Empty Activity". That will generate two files; a java file and an xml file, just like the previous versions. So file > New > New Project


If you look in activity_main.xml (or main_activity.xml - whatever it's called), you should see the line <include layout="@layout/content_main"/> . As you might expect, this includes the content of content_main.xml in this position within the activity_main.xml layout. To make things easier to understand in conjunction with your book, you can just cut and paste everything in content_main.xml to replace that line.
There are a couple of reasons why <include /> is useful. First, it allows you to reuse your layout xml across multiple files. Second, it means that you can specify different layouts depending on the configuration of the device. For an example of this, take a look at what happens with activity_item_list.xml and item_list.xml when you make a new Master/Detail Flow.


Just delete the extra xml's and files . And it would be like old Template . For example :

Delete content_main.xml and all the error comes after doing this . And it would back to old Template . Also , you can choose Empty Activity , it would be like old one more .

see this and u would get your answer : What is the role of content_main.xml in android studio 1.4?

链接地址: http://www.djcxy.com/p/88202.html

上一篇: 在iOS 9中设置UIView的碰撞边界路径

下一篇: 新的Android Studio活动设计模式内容