Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New Android Studio Activity Design Pattern content_main.xml

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.

like image 229
Timbo Avatar asked Oct 14 '15 10:10

Timbo


2 Answers

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

like image 63
N Suhaib Avatar answered Sep 28 '22 21:09

N Suhaib


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.

like image 28
Martin Avatar answered Sep 28 '22 19:09

Martin