상세 컨텐츠

본문 제목

안드로이드 content_main 과 activity_main

개발/안드로이드 개발

by 똘똘이박사 2015. 10. 6. 19:12

본문

· 최초작성 : 2015. 10. 06.

· 최종수정 : 2015. 10. 06.

· 작성/수정내용 :

  - 안드로이드 스튜디오 1.4 업그레이드 후 Content_main.xml 





시작하기에 앞서...


오늘 안드로이드 스튜디오를 1.4 버전으로 업그레이드 시켰더니

새 프로젝트를 생성할 때 새로운 방식으로 디자인 방식이 변경되었네요.

영문도 모르고 뭐가 잘 못된줄 알고 껐다 켰다, 프로젝트를 삭제했다가 다시 생성해보기를 몇 번 씩 해보다가

아~ 이게 에러가 아니고 다른 뭔가가 있겠구나 싶더라구요

그래서 이번 포스팅에서는 왜 그런지 생각해 볼께요




# content_main.xml  와 activity_main.xml







안드로이드 스튜디오를 1.4로 업데이트하고 '새 프로젝트'를 생성한 분들은 모두 당황하셨을 겁니다.

저도 무척 당황해서 여기 저기 찾아 봤는데 딱히 자세히 나와 있는 부분은 찾지 못했습니다.

업데이트 도큐먼트라도 찾아 보려고 했는데 아직 찾지 못해서 소스로만 파악한 내용과 다른 블로그에서 찾아본 내용을 정리해 봅니다.



'content_main.xml' 이 만들어진 이유는 안드로이스 스튜디오 1.4로 업그레이드 되면서 적용된 

새로운 디자인패턴 정책의 결과물 이라고 합니다.



content_main.xml 은 기존 activity_main.xml 에서과 완전히 동일한 기능을 수행하는 것으로 보입니다.

즉, Layout, TextView, Button 등의 그림 그리는 일은 이제 'content_main.xml'에서 하면 되는 것입니다. 

그리고 activity_main.xml 에서는 content_main.xml 을 포함시킵니다.


그럼 activity_main.xml 은 또 뭘 하는 거지????


우선 새로운 디자인패턴이 적용된 activity_main.xml 을 기본 소스를 보겠습니다.


<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main" />

<android.support.design.widget.FloatingActionButton android:id="@+id/fab"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>


activity_main.xml 중간에 include 문이 있습니다.

<include layout="@layout/content_main" />


동일 경로안에 content_main.xml 을 include 하는 것을 볼 수 있네요


따라서 위 소스로 보아 activity_main.xml에서 coordinatorLayout 나 AppBarLayout 에 대한 설정을

간단히 추가 할 수 있도록 뭔가 구분하려고 하는것 같습니다.

즉 화면에 그림 그리는 일과 시스템적?? 으로 별도의 설정이 필요한 부분을 나누기 위한 것으로 생각됩니다.


더 자세한 디자인패턴에 변화에 대한 이유는 차차 알아볼 과제 인거 같습니다.



그리고 한 가지 더~~~~!!!!

기본 프로젝트를 생성하면 이메일 아이콘이 생기더군요

근데 이건 왜 content_mail.xml 에 정의 된거야????






반응형

관련글 더보기