### : 목차 구분 기호
--- : 목차 내에 항목 구분 기호
@@@ : 태그 용도 
,,, : 같은 목차 내에 구분 기호

목차
1. 이론 및 정보
2. 설정 및 그 밖에
3. 소스코드 또는 실습
4. 과제

###################################
1. 이론 및 정보
-----------------------------------
* 프로젝트를 관리해주는 툴
Maven - 별도 라이브러리를 복사하지 않아도 됨
Gradle - 최신 트랜드, 프로젝트 관리
----------------------------------- 
* TabLayout 대신에 FragmentLayout을 권장
----------------------------------- 
* TableLayout
한개의 View가 하나의 열이 됨, 따로 없음
----------------------------------- 
* GridLayout은 TableLayout을 보완한 Layout
----------------------------------- 
* GridLayout 참고 블로그 
http://android-developers.blogspot.kr/2011/11/new-layout-widgets-space-and-gridlayout.html
-----------------------------------  
###################################
2. 설정 및 그 밖에
-----------------------------------
* 안드로이드 스튜디오 설치
안드로이드 스튜디오가 인텔리제이(IntelliJ) 엔진을 쓰고 있음
----------------------------------- 
* 예전 버전 지원하는 라이브러리, 사용법
~\study\android-sdk\extras\android\support
TabActivity 사용하려는데 문제가 발생
activity_tab.xml에 ID를 주는데 문제였음

하지만 실제로 필요한 경우에는 Build Path에서
라이브러리 추가하는데, GridLayout 같은 경우 아래와 같은 경로로 찾는다
~\study\android-sdk\extras\android\support\v7\appcompat\libs\android-support-v7-appcompat.jar
----------------------------------- 
###################################
3. 소스코드 또는 실습 
-----------------------------------
3-1
WorkSpace : ~\study\AndroidWork 
/LayoutApp/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.layoutapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="19"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="LinearActivity" >
        </activity>
        <activity android:name="RelativeActivity" >
        </activity>
        <activity android:name="FrameActivity" >
        </activity>
        <activity android:name="TabActivitiy" >
        </activity>
        <activity android:name="Sub1Activity" >
        </activity>
        <activity android:name="Sub2Activity" >
        </activity>
        <activity android:name="Sub3Activity" >
        </activity>
        <activity android:name="TableActivity" >
        </activity>
        <activity android:name="GridActivity" >
        </activity>
    </application>

</manifest>
----------------------------------- 
3-2
WorkSpace : ~\study\AndroidWork
/LayoutApp/src/com/example/layoutapp/MainActivity.java

package com.example.layoutapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener {

     @Override
     protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Button btnLinear = (Button) findViewById(R.id.btnLinear);
          Button btnRelative = (Button) findViewById(R.id.btnRelative);
          Button btnFrame = (Button) findViewById(R.id.btnFrame);
          Button btnTab = (Button) findViewById(R.id.btnTab);
          Button btnTable = (Button) findViewById(R.id.btnTable);
          Button btnGrid = (Button) findViewById(R.id.btnGrid);

          btnLinear.setOnClickListener(this);
          btnRelative.setOnClickListener(this);
          btnFrame.setOnClickListener(this);
          btnTab.setOnClickListener(this);
          btnTable.setOnClickListener(this);
          btnGrid.setOnClickListener(this);
     }

     @Override
     public void onClick(View v) {
          Intent intent = null;
          switch (v.getId()) {
          case R.id.btnLinear:
               intent = new Intent(MainActivity.this, LinearActivity.class);
               break;
          case R.id.btnRelative:
               intent = new Intent(MainActivity.this, RelativeActivity.class);
               break;
          case R.id.btnFrame:
               intent = new Intent(MainActivity.this, FrameActivity.class);
               break;
          case R.id.btnTab:
               intent = new Intent(MainActivity.this, TabActivitiy.class);
               break;
          case R.id.btnTable:
               intent = new Intent(MainActivity.this, TableActivity.class);
               break;
          case R.id.btnGrid:
               intent = new Intent(MainActivity.this, GridActivity.class);
               break;
          }
          if (intent != null) {
               startActivity(intent);
          }
     }

}
----------------------------------- 
3-3
WorkSpace : ~\study\AndroidWork
/LayoutApp/res/layout/activity_frame.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/tulips"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="FrameLayout Test"
        android:textSize="20dp" />
    <!--
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:onClick="showImage"
        android:text="Show Image" />
    -->

    <Button
        android:id="@+id/btnShow"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="Show Image"/>
   
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ImageView
            android:id="@+id/img1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/desert"
            android:visibility="visible" />

        <ImageView
            android:id="@+id/img2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/penguins"
            android:visibility="invisible" />
    </FrameLayout>

</LinearLayout>
----------------------------------- 
3-4
WorkSpace : ~\study\AndroidWork
/LayoutApp/src/com/example/layoutapp/FrameActivity.java

package com.example.layoutapp;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class FrameActivity extends Activity {
     private Button btnShow;
     private ImageView img1, img2;
     private boolean toggle = true;

     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_frame);
         img1 = (ImageView)findViewById(R.id.img1);
         img2 = (ImageView)findViewById(R.id.img2);        
         btnShow = (Button)findViewById(R.id.btnShow);
         btnShow.setOnClickListener(new OnClickListener() {
               @Override
               public void onClick(View v) {
                    toggle = !toggle;
                    if(toggle == true){
                         img1.setVisibility(View.VISIBLE);
                         img2.setVisibility(View.INVISIBLE);
                    }else{
                         img1.setVisibility(View.INVISIBLE);
                         img2.setVisibility(View.VISIBLE);
                    }    
               }
          });
     }
    
     public void showImage(View v){
//          Toast.makeText(getApplicationContext(), "test", Toast.LENGTH_SHORT).show();
          toggle = !toggle;
          if(toggle == true){
               img1.setVisibility(View.VISIBLE);
               img2.setVisibility(View.INVISIBLE);
          }else{
               img1.setVisibility(View.INVISIBLE);
               img2.setVisibility(View.VISIBLE);
          }    
     }

}
----------------------------------- 
3-5 
WorkSpace : ~\study\AndroidWork
/LayoutApp/res/layout/activity_tab.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="TabLayout Test"
        android:textSize="20dp" />

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </LinearLayout>
    </TabHost>

</LinearLayout>
----------------------------------- 
3-6
WorkSpace : ~\study\AndroidWork
/LayoutApp/src/com/example/layoutapp/TabActivitiy.java

package com.example.layoutapp;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;

public class TabActivitiy extends TabActivity{

     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_tab);
        
         TabHost tabhost = getTabHost();// TabHost의 주소를 가져옴
         TabHost.TabSpec spec = tabhost.newTabSpec("tab01");
         Intent intent = new Intent(getApplicationContext(),Sub1Activity.class);
         spec.setContent(intent);
         spec.setIndicator("First Tab");// tab 모양 지정
         tabhost.addTab(spec);
        
         spec = tabhost.newTabSpec("tab02");
         intent = new Intent(getApplicationContext(),Sub2Activity.class);
         spec.setContent(intent);
         spec.setIndicator("Second Tab");// tab 모양 지정
         tabhost.addTab(spec);
        
         spec = tabhost.newTabSpec("tab03");
         intent = new Intent(getApplicationContext(),Sub3Activity.class);
         spec.setContent(intent);
         spec.setIndicator("Third Tab");// tab 모양 지정
         tabhost.addTab(spec);
        
         tabhost.setCurrentTab(2);// 처음에 보여질 tab 설정, 0부터 시작
     }

}
----------------------------------- 
3-7 
WorkSpace : ~\study\AndroidWork
/LayoutApp/res/layout/tab_sub1.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ff0000cc"
        android:gravity="center"
        android:text="First Page"
        android:textColor="#ffffffff"
        android:textSize="20dp" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="First Button"
        android:textStyle="bold" />

</LinearLayout>
----------------------------------- 
3-8 
WorkSpace : ~\study\AndroidWork
/LayoutApp/res/layout/tab_sub2.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ff0000cc"
        android:gravity="center"
        android:text="Second Page"
        android:textColor="#ffffffff"
        android:textSize="20dp" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Second Button"
        android:textStyle="bold" />

</LinearLayout>
----------------------------------- 
3-9 
WorkSpace : ~\study\AndroidWork
/LayoutApp/res/layout/tab_sub3.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ff0000cc"
        android:gravity="center"
        android:text="Third Page"
        android:textColor="#ffffffff"
        android:textSize="20dp" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Third Button"
        android:textStyle="bold" />

</LinearLayout>
----------------------------------- 
3-10 
WorkSpace : ~\study\AndroidWork
/LayoutApp/src/com/example/layoutapp/Sub1Activity.java

package com.example.layoutapp;

import android.app.Activity;
import android.os.Bundle;

public class Sub1Activity extends Activity {

     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.tab_sub1);
     }

}
----------------------------------- 
3-11 
WorkSpace : ~\study\AndroidWork
/LayoutApp/src/com/example/layoutapp/Sub2Activity.java

package com.example.layoutapp;

import android.app.Activity;
import android.os.Bundle;

public class Sub2Activity extends Activity {

     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.tab_sub2);
     }

}
----------------------------------- 
3-12 
WorkSpace : ~\study\AndroidWork
/LayoutApp/src/com/example/layoutapp/Sub3Activity.java

package com.example.layoutapp;

import android.app.Activity;
import android.os.Bundle;

public class Sub3Activity extends Activity {

     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.tab_sub3);
     }

}
----------------------------------- 
3-13 
WorkSpace : ~\study\AndroidWork
/LayoutApp/src/com/example/layoutapp/TableActivity.java

package com.example.layoutapp;

import android.app.Activity;
import android.os.Bundle;

public class TableActivity extends Activity {

     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_table);
     }

}
----------------------------------- 
3-14 
WorkSpace : ~\study\AndroidWork
/LayoutApp/res/layout/activity_table.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="TableLayout Test"
        android:textSize="20dp" />

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="0,1,2" >

        <TableRow>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="First Button" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Second Button" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Third Button" />
        </TableRow>

        <TableRow android:background="#00AA00" >

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Forth Button" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Fifth Button" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Sixth Button" />
        </TableRow>

        <TableRow>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="3"
                android:text="Seventh Button" />
        </TableRow>
    </TableLayout>

</LinearLayout>
----------------------------------- 
3-15 
WorkSpace : ~\study\AndroidWork
/LayoutApp/src/com/example/layoutapp/GridActivity.java

package com.example.layoutapp;

import android.app.Activity;
import android.os.Bundle;

public class GridActivity extends Activity {

     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_grid);
     }

}
----------------------------------- 
3-16 
WorkSpace : ~\study\AndroidWork
/LayoutApp/res/layout/activity_grid.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="GridLayout Test"
        android:textSize="20sp" />
   
</LinearLayout>
----------------------------------- 
###################################
4. 과제
-----------------------------------
-----------------------------------
###################################
5. 과제 해결
-----------------------------------
-----------------------------------
###################################
6. 기타
----------------------------------- 
----------------------------------- 


'OpenFrameWork' 카테고리의 다른 글

오픈프레임워크_Day74  (0) 2015.06.29
오픈프레임워크_Day73  (0) 2015.06.26
오픈프레임워크_Day71  (0) 2015.06.24
오픈프레임워크_Day70  (0) 2015.06.23
오픈프레임워크_Day69  (0) 2015.06.22
,